jdereg / json-io

Convert Java to JSON. Convert JSON to Java. Pretty print JSON. Java JSON serializer. Deep copy Java object graphs.
Apache License 2.0
326 stars 107 forks source link

Could not find class: java.time.ZoneRules which has associated alias value: ZoneRules config/aliases.txt #285

Closed skwakman closed 2 weeks ago

skwakman commented 2 weeks ago

Description

When creating a new instance of either ReadOptions or WriteOptions, an error message is being logged by the json-io library. Regardless of the message, json-io does seem to continue reading and writing json just fine. But the error does confuse end-users and developers into thinking something is not working properly.

The message: Could not find class: java.time.ZoneRules which has associated alias value: ZoneRules config/aliases.txt

How to reproduce

Create a new instance of either ReadOptions or WriteOptions using the builder and the message will be logged System.out.

// either one will trigger the message log
ReadOptions readOptions = new ReadOptionsBuilder().build();
WriteOptions writeOptions = new WriteOptionsBuilder().build();

This message appears since using json-io 2.24.0, observed using the following JDKs (all on aarch64/mac m1)

This message does not appear in json-io version 2.23.0.

Possible cause

The message seems to be generated from within com.cedarsoftware.util.ClassUtilities. In that class' loadClass method, attempts are made to load the class but all return a null value:

try {
  currentClass = classLoader.loadClass(className); // this returns null
} catch (ClassNotFoundException var7) {
  currentClass = Thread.currentThread().getContextClassLoader().loadClass(className); // this also returns null, triggering the error message
}

My guess is, an incorrect package for the ZoneRules class is listed in aliases.txt. In that file, a class named 'java.time.ZoneRules' is listed. If that class should correspond to the JDK's own ZoneRules class, it should be java.time.zone.ZoneRules.

jdereg commented 2 weeks ago

Sannie,

This is a very clear description of the issue - thank you. We are release an updated java-util and json-io this weekend (June 22-23rd). The 2.25.0 will contain this correction.

On Fri, Jun 21, 2024 at 8:01 AM Sannie Kwakman @.***> wrote:

Description

When creating a new instance of either ReadOptions or WriteOptions, an error message is being logged by the json-io library. Regardless of the message, json-io does seem to continue reading and writing json just fine. But the error does confuse end-users and developers into thinking something is not working at all.

The message: Could not find class: java.time.ZoneRules which has associated alias value: ZoneRules config/aliases.txt How to reproduce

Create a new instance of either ReadOptions or WriteOptions using the builder and the message will be logged System.out.

// either one will trigger the message log ReadOptions readOptions = new ReadOptionsBuilder().build(); WriteOptions writeOptions = new WriteOptionsBuilder().build();

This message appears since using json-io 2.24.0, observed using the following JDKs (all on aarch64/mac m1)

  • temurin 11.0.23
  • temurin 17.0.11
  • openjdk 22.0.1

This message does not appear in json-io version 2.23.0. Possible cause

The message seems to be generated from within com.cedarsoftware.util.ClassUtilities. In that class' loadClass method, attempts are made to load the class but all return a null value:

try { currentClass = classLoader.loadClass(className); // this returns null } catch (ClassNotFoundException var7) { currentClass = Thread.currentThread().getContextClassLoader().loadClass(className); // this also returns null, triggering the error message }

My guess is, an incorrect package for the ZoneRules class is listed in aliases.txt. In that file, a class named 'java.time.ZoneRules' is listed. If that class should correspond to the JDK's own ZoneRules class, it should be java.time.zone.ZoneRules.

— Reply to this email directly, view it on GitHub https://github.com/jdereg/json-io/issues/285, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABI76TQI6NUCMZDRMNZ4ADDZIQI23AVCNFSM6AAAAABJVXZ2KSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM3DMMZZHA2DEMI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jdereg commented 2 weeks ago

This has been corrected in json-io 4.25.0.