File tree Expand file tree Collapse file tree 2 files changed +44
-5
lines changed
modules/openapi-generator/src
main/java/org/openapitools/codegen/config
test/java/org/openapitools/codegen/config Expand file tree Collapse file tree 2 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -38,12 +38,13 @@ public class GlobalSettings {
3838
3939 private static final Logger LOGGER = LoggerFactory .getLogger (GlobalSettings .class );
4040
41- private static ThreadLocal <Properties > properties = new InheritableThreadLocal <Properties >() {
41+ private static ThreadLocal <Properties > properties = new InheritableThreadLocal <>() {
4242 @ Override
4343 protected Properties initialValue () {
4444 // avoid using System.getProperties().clone() which is broken in Gradle - see https://github.com/gradle/gradle/issues/17344
4545 Properties copy = new Properties ();
46- copy .putAll (System .getProperties ());
46+ System .getProperties ()
47+ .forEach ((k ,v ) -> copy .put (String .valueOf (k ), String .valueOf (v )));
4748 return copy ;
4849 }
4950 };
@@ -69,8 +70,10 @@ public static void reset() {
6970 }
7071
7172 public static void log () {
72- StringWriter stringWriter = new StringWriter ();
73- properties .get ().list (new PrintWriter (stringWriter ));
74- LOGGER .debug ("GlobalSettings: {}" , stringWriter );
73+ if (LOGGER .isDebugEnabled ()) {
74+ StringWriter stringWriter = new StringWriter ();
75+ properties .get ().list (new PrintWriter (stringWriter ));
76+ LOGGER .debug ("GlobalSettings: {}" , stringWriter );
77+ }
7578 }
7679}
Original file line number Diff line number Diff line change 1+ package org .openapitools .codegen .config ;
2+
3+ import ch .qos .logback .classic .Level ;
4+ import ch .qos .logback .classic .Logger ;
5+ import java .util .Properties ;
6+ import static org .assertj .core .api .Assertions .assertThat ;
7+ import static org .assertj .core .api .Assertions .assertThatNoException ;
8+ import org .slf4j .LoggerFactory ;
9+ import org .testng .annotations .BeforeClass ;
10+ import org .testng .annotations .Test ;
11+
12+ /**
13+ * Test class for {@link GlobalSettings}
14+ * @author Edoardo Patti
15+ */
16+ public class GlobalSettingsTest {
17+
18+ private static final Object OBJECT = new Object ();
19+
20+ @ BeforeClass
21+ public void setUp () {
22+ ((Logger ) LoggerFactory .getLogger (GlobalSettings .class )).setLevel (Level .DEBUG );
23+ Properties props = new Properties (2 );
24+ props .put ("test1" , OBJECT );
25+ props .put (OBJECT , "test2" );
26+ System .getProperties ().putAll (props );
27+ }
28+
29+ @ Test
30+ public void testNonStringSystemProperties () {
31+ assertThat (GlobalSettings .getProperty (OBJECT .toString ())).isNotNull ();
32+ assertThat (GlobalSettings .getProperty ("test1" )).isNotNull ();
33+ assertThatNoException ().isThrownBy (GlobalSettings ::log );
34+ }
35+
36+ }
You can’t perform that action at this time.
0 commit comments