forked from reactor/reactor-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix reactor#985 Prevent NPE when debug mode is activated via command …
…line This commit fixes an NPE and subsequent initialization error when the debug mode is activated through the `reactor.trace.operatorStacktrace` System property, by correctly reordering the static fields and blocks. Additionally, the debug mode via command line also uses the correct hook key, so that activating via System property then deactivating via Hooks method would work. Finally, this behavior is tested as an additional test task in Gradle, ensuring the property is set and no previous classloading of Hooks has been done by other tests.
- Loading branch information
1 parent
14d607b
commit 75a0ab0
Showing
3 changed files
with
107 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
reactor-core/src/test/java/reactor/core/publisher/HooksTestStaticInit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2011-2017 Pivotal Software Inc, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* Copyright (c) 2011-2017 Pivotal Software Inc, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package reactor.core.publisher; | ||
|
||
import org.junit.After; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class HooksTestStaticInit { | ||
|
||
//IMPORTANT: this test case depends on System property | ||
// `reactor.trace.operatorStacktrace` be set to `true` | ||
|
||
@After | ||
public void resetAllHooks() { | ||
Hooks.resetOnOperatorError(); | ||
Hooks.resetOnNextDropped(); | ||
Hooks.resetOnErrorDropped(); | ||
// Hooks.resetOnOperatorDebug(); //superseded by resetOnEachOperator | ||
Hooks.resetOnEachOperator(); | ||
Hooks.resetOnLastOperator(); | ||
} | ||
|
||
@Test | ||
public void syspropDebugModeShouldNotFail() { | ||
assertThat(System.getProperties()) | ||
.as("debug mode set via system property") | ||
.containsEntry("reactor.trace.operatorStacktrace", "true"); | ||
assertThat(Hooks.getOnEachOperatorHooks()) | ||
.as("debug hook activated") | ||
.containsKey(Hooks.ON_OPERATOR_DEBUG_KEY); | ||
//would throw NPE due to https://github.com/reactor/reactor-core/issues/985 | ||
Mono.just("hello").subscribe(); | ||
} | ||
|
||
} |