Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly broken config: Json-io config refers to its own classes by fully qualified name in config files, but java-cfenv shades it, renaming its classes. #275

Closed
jangroothuijse opened this issue Sep 10, 2024 · 3 comments

Comments

@jangroothuijse
Copy link

jangroothuijse commented Sep 10, 2024

In java-cfenv

Here json-io is shaded:
https://github.com/pivotal-cf/java-cfenv/blob/main/java-cfenv-all/build.gradle#L39

shadowJar {
    archiveClassifier.set('')
    mergeServiceFiles()
    transform(PropertiesFileTransformer) {
        paths = ['META-INF/spring.factories']
        mergeStrategy = "append"
    }
    dependencies {
        exclude(dependency('org.springframework.boot::'))
        exclude(dependency('org.springframework::'))
    }
    relocate 'com.cedarsoftware.io', 'io.pivotal.cfenv.shaded.com.cedarsoftware.io'
}

In json-io

Here json-io refers to itself:
https://github.com/jdereg/json-io/blob/master/src/main/resources/config/classFactory.txt#L73

# interface instantiates to...
java.util.Collection = com.cedarsoftware.io.factory.CollectionFactory

The reference com.cedarsoftware.io.factory.CollectionFactory is now wrong, it should io.pivotal.cfenv.shaded.com.cedarsoftware.io.factory.CollectionFactory.

This generates this console output while deploying the app (while the jar it is starting up):

Skipping class: com.cedarsoftware.io.factory.CollectionFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Queue

Which is produced here:
https://github.com/jdereg/json-io/blob/47fe31aa3996fff6963fcf7ce65dcf2eb46dbb09/src/main/java/com/cedarsoftware/io/ReadOptionsBuilder.java#L722

System.out.println("Skipping class: " + className + " not defined in JVM, but listed in resources/classFactories.txt");

Which is triggered by a static initializer:
https://github.com/jdereg/json-io/blob/47fe31aa3996fff6963fcf7ce65dcf2eb46dbb09/src/main/java/com/cedarsoftware/io/ReadOptionsBuilder.java#L77

    static {
        // ClassFactories
        loadBaseClassFactory();
        loadBaseReaders();
        loadBaseAliasMappings(ReadOptionsBuilder::addPermanentAlias);
        loadBaseCoercedTypes();
        loadBaseNonRefs();
        loadBaseFieldsNotImported();
        loadBaseNonStandardSetters();

        defReadOptions = new ReadOptionsBuilder().build();
    }

In our app, the console output was the only unexpected behavior. However, to me it seems more could be broken here.
Possible fixes:

  • do not shade the dependency
  • add config files to override the ones from json-io
@anthonydahanne
Copy link
Member

Hello @jangroothuijse
Thank you for your bug report, I've also experienced something very similar with the all in one jar , java-cf-env-all
Looking into it!

@anthonydahanne
Copy link
Member

Here are the logs I had

Skipping class: com.cedarsoftware.io.factory.StackTraceElementFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.lang.StackTraceElement
Skipping class: com.cedarsoftware.io.factory.CollectionFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collection
Skipping class: com.cedarsoftware.io.factory.CollectionFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.List
Skipping class: com.cedarsoftware.io.factory.CollectionFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Set
Skipping class: com.cedarsoftware.io.factory.CollectionFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.SortedSet
Skipping class: com.cedarsoftware.io.factory.CollectionFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.NavigableSet
Skipping class: com.cedarsoftware.io.factory.CollectionFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Deque
Skipping class: com.cedarsoftware.io.factory.CollectionFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Queue
Skipping class: com.cedarsoftware.io.factory.MapFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Map
Skipping class: com.cedarsoftware.io.factory.MapFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.SortedMap
Skipping class: com.cedarsoftware.io.factory.MapFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.NavigableMap
Skipping class: com.cedarsoftware.io.factory.CharacterPrimArrayFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: [C
Skipping class: com.cedarsoftware.io.factory.EmptyEnumerationFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$EmptyEnumeration
Skipping class: com.cedarsoftware.io.factory.EmptyIteratorFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$EmptyIterator
Skipping class: com.cedarsoftware.io.factory.EmptyListIteratorFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$EmptyListIterator
Skipping class: com.cedarsoftware.io.factory.EmptyListFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$EmptyList
Skipping class: com.cedarsoftware.io.factory.EmptySetFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$EmptySet
Skipping class: com.cedarsoftware.io.factory.EmptyNavigableSetFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$UnmodifiableNavigableSet$EmptyNavigableSet
Skipping class: com.cedarsoftware.io.factory.EmptyMapFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$EmptyMap
Skipping class: com.cedarsoftware.io.factory.EmptyNavigableMapFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$UnmodifiableNavigableMap$EmptyNavigableMap
Skipping class: com.cedarsoftware.io.factory.SealableListFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$UnmodifiableCollection
Skipping class: com.cedarsoftware.io.factory.SealableListFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$UnmodifiableList
Skipping class: com.cedarsoftware.io.factory.SealableListFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$UnmodifiableRandomAccessList
Skipping class: com.cedarsoftware.io.factory.SealableSetFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$UnmodifiableSet
Skipping class: com.cedarsoftware.io.factory.SealableNavigableSetFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$UnmodifiableSortedSet
Skipping class: com.cedarsoftware.io.factory.SealableNavigableSetFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$UnmodifiableNavigableSet
Skipping class: com.cedarsoftware.io.factory.SealableMapFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$UnmodifiableMap
Skipping class: com.cedarsoftware.io.factory.SealableNavigableMapFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$UnmodifiableSortedMap
Skipping class: com.cedarsoftware.io.factory.SealableNavigableMapFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.Collections$UnmodifiableNavigableMap
Skipping class: com.cedarsoftware.io.factory.SealableListFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: com.cedarsoftware.util.SealableList
Skipping class: com.cedarsoftware.io.factory.SealableSetFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: com.cedarsoftware.util.SealableSet
Skipping class: com.cedarsoftware.io.factory.SealableNavigableSetFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: com.cedarsoftware.util.SealableNavigableSet
Skipping class: com.cedarsoftware.io.factory.SealableMapFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: com.cedarsoftware.util.SealableMap
Skipping class: com.cedarsoftware.io.factory.SealableNavigableMapFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: com.cedarsoftware.util.SealableNavigableMap
Skipping class: com.cedarsoftware.io.factory.ImmutableListFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.ImmutableCollections$ListN
Skipping class: com.cedarsoftware.io.factory.ImmutableListFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.ImmutableCollections$List12
Skipping class: com.cedarsoftware.io.factory.ImmutableSetFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.ImmutableCollections$SetN
Skipping class: com.cedarsoftware.io.factory.ImmutableSetFactory not defined in JVM, but listed in resources/classFactories.txt, as factory for: java.util.ImmutableCollections$Set12
Could not find class: com.cedarsoftware.io.util.SingletonList which has associated alias value: SingletonList config/aliases.txt
Could not find class: com.cedarsoftware.io.util.SingletonSet which has associated alias value: SingletonSet config/aliases.txt
Could not find class: com.cedarsoftware.io.util.SingletonMap which has associated alias value: SingletonMap config/aliases.txt
Skipping class coercion for source class: java.util.Collections$SingletonList cannot be mapped to: com.cedarsoftware.io.util.SingletonList (not found), listed in resources/coercedTypes.txt
Skipping class coercion for source class: java.util.Collections$SingletonSet cannot be mapped to: com.cedarsoftware.io.util.SingletonSet (not found), listed in resources/coercedTypes.txt
Skipping class coercion for source class: java.util.Collections$SingletonMap cannot be mapped to: com.cedarsoftware.io.util.SingletonMap (not found), listed in resources/coercedTypes.txt
Could not find class: com.cedarsoftware.io.util.SingletonList which has associated alias value: SingletonList config/aliases.txt
Could not find class: com.cedarsoftware.io.util.SingletonSet which has associated alias value: SingletonSet config/aliases.txt
Could not find class: com.cedarsoftware.io.util.SingletonMap which has associated alias value: SingletonMap config/aliases.txt
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: boolean
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: boolean
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$CharacterWriter, listed in resources/customWriters.txt as a custom writer for: char
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$CharacterWriter, listed in resources/customWriters.txt as a custom writer for: char
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$DoubleWriter, listed in resources/customWriters.txt as a custom writer for: double
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$DoubleWriter, listed in resources/customWriters.txt as a custom writer for: double
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$FloatWriter, listed in resources/customWriters.txt as a custom writer for: float
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$FloatWriter, listed in resources/customWriters.txt as a custom writer for: float
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: int
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: int
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.writers.LongWriter, listed in resources/customWriters.txt as a custom writer for: long
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.writers.LongWriter, listed in resources/customWriters.txt as a custom writer for: long
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: short
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: short
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Boolean
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Boolean
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Byte
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Byte
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$CharacterWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Character
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$CharacterWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Character
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$ClassWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Class
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$ClassWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Class
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$DoubleWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Double
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$DoubleWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Double
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$FloatWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Float
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$FloatWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Float
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Integer
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Integer
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.writers.LongWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Long
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.writers.LongWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Long
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Short
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveValueWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.Short
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$JsonStringWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.String
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$JsonStringWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.String
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveUtf8StringWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.StringBuffer
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveUtf8StringWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.StringBuffer
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveUtf8StringWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.StringBuilder
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveUtf8StringWriter, listed in resources/customWriters.txt as a custom writer for: java.lang.StringBuilder
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$BigDecimalWriter, listed in resources/customWriters.txt as a custom writer for: java.math.BigDecimal
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$BigDecimalWriter, listed in resources/customWriters.txt as a custom writer for: java.math.BigDecimal
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$BigIntegerWriter, listed in resources/customWriters.txt as a custom writer for: java.math.BigInteger
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$BigIntegerWriter, listed in resources/customWriters.txt as a custom writer for: java.math.BigInteger
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveUtf8StringWriter, listed in resources/customWriters.txt as a custom writer for: java.net.URL
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveUtf8StringWriter, listed in resources/customWriters.txt as a custom writer for: java.net.URL
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveUtf8StringWriter, listed in resources/customWriters.txt as a custom writer for: java.net.URI
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$PrimitiveUtf8StringWriter, listed in resources/customWriters.txt as a custom writer for: java.net.URI
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$DateAsLongWriter, listed in resources/customWriters.txt as a custom writer for: java.sql.Date
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$DateAsLongWriter, listed in resources/customWriters.txt as a custom writer for: java.sql.Date
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$TimestampWriter, listed in resources/customWriters.txt as a custom writer for: java.sql.Timestamp
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$TimestampWriter, listed in resources/customWriters.txt as a custom writer for: java.sql.Timestamp
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.writers.DurationWriter, listed in resources/customWriters.txt as a custom writer for: java.time.Duration
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.writers.DurationWriter, listed in resources/customWriters.txt as a custom writer for: java.time.Duration
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.writers.InstantWriter, listed in resources/customWriters.txt as a custom writer for: java.time.Instant
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.writers.InstantWriter, listed in resources/customWriters.txt as a custom writer for: java.time.Instant
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$LocalDateWriter, listed in resources/customWriters.txt as a custom writer for: java.time.LocalDate
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$LocalDateWriter, listed in resources/customWriters.txt as a custom writer for: java.time.LocalDate
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$LocalDateTimeWriter, listed in resources/customWriters.txt as a custom writer for: java.time.LocalDateTime
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$LocalDateTimeWriter, listed in resources/customWriters.txt as a custom writer for: java.time.LocalDateTime
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$LocalTimeWriter, listed in resources/customWriters.txt as a custom writer for: java.time.LocalTime
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$LocalTimeWriter, listed in resources/customWriters.txt as a custom writer for: java.time.LocalTime
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$MonthDayWriter, listed in resources/customWriters.txt as a custom writer for: java.time.MonthDay
Note: class failed to instantiate (a custom JsonClassWriter class): com.cedarsoftware.io.Writers$MonthDayWriter, listed in resources/customWriters.txt as a custom writer for: java.time.MonthDay
Note: class not found (custom JsonClassWriter class): com.cedarsoftware.io.Writers$OffsetDateTimeWriter, listed in resources/customWriters.txt as a custom writer for: java.time.OffsetDateTime

@anthonydahanne
Copy link
Member

Here are the four text files (in resources/config) to "transform" during shading

  • aliases.txt
  • classFactory.txt
  • coercedTypes.txt
  • customWriters.txt

anthonydahanne added a commit that referenced this issue Oct 29, 2024
* upgrade to latest Gradle Shadow plugin
* add new transformer that replaces the original package name in text files in the json-io config folder (aliases.txt, classFactory.txt, coercedTypes.txt, customWriters.txt) with the shaded one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants