Dynatrace / openkit-java

OpenKit Java Reference Implementation
Apache License 2.0
35 stars 34 forks source link

openkit-1.0.1-java6.jar is not usable with Java 6 #105

Closed hjembaek closed 6 years ago

hjembaek commented 6 years ago

When DynatraceOpenKitBuilder is initialized with build() - it fails with the stacktrace below on Java 6.

Calling this:

openKit = new DynatraceOpenKitBuilder(BEACON_URL, APP_ID, deviceID).withApplicationName(APP_NAME).withApplicationVersion("1.0.0.0").withOperatingSystem(os).withManufacturer(domain).withModelID(ProcessUtil.getProcessIdAndHost()).enableVerbose().build();

Gives the following error at runtime:

java.lang.ExceptionInInitializerError at java.lang.J9VMInternals.initialize(J9VMInternals.java:222) at com.dynatrace.openkit.AbstractOpenKitBuilder.getLogger(AbstractOpenKitBuilder.java:260) at com.dynatrace.openkit.AbstractOpenKitBuilder.build(AbstractOpenKitBuilder.java:207) at UDynatrace.initDynatraceOpenKit(UDynatrace.java:144)

... cut out ...

Caused by: java.lang.IllegalArgumentException: Illegal pattern character 'X' at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:786) at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:587) at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:512) at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:487) at com.dynatrace.openkit.core.util.DefaultLogger.<clinit>(DefaultLogger.java:32) at java.lang.J9VMInternals.initializeImpl(Native Method) at java.lang.J9VMInternals.initialize(J9VMInternals.java:200) ... 75 more

The error arises because Java 6 does not support the SimpleDateFormat type 'X' -> https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

Workaround

Create a new Logger implementation and change the DATEFORMAT so it does not contain X in the format.

static final String DATEFORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS";

stefaneberl commented 6 years ago

Proposed solution: Instead of using the X timezone specifier, which does not exist in Java 6, the timezone specifier Z shall be used. Regarding the documentation, this exists for Java 6 as well.

stefaneberl commented 6 years ago

Having a closer look on the code, @hjembaek you are right! Since the timezone in use is UTC, we do not need any TZ specific formatting.

hjembaek commented 6 years ago

Thank you 👍

stefaneberl commented 6 years ago

I'm closing this issue. A bugfix release is available for 1.0.X (see https://github.com/Dynatrace/openkit-java/releases/tag/v1.0.2).

For newer OpenKit Java versions, a bugfix release will come soon.