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

...-with-dependencies.jar fails with NoClassDefFoundError #144

Closed
Marcono1234 opened this issue Aug 1, 2022 · 1 comment
Closed

...-with-dependencies.jar fails with NoClassDefFoundError #144

Marcono1234 opened this issue Aug 1, 2022 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@Marcono1234
Copy link
Contributor

Bug description

lingua-1.2.1-with-dependencies.jar fails with NoClassDefFoundError:

Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError
        at java.base/java.util.concurrent.ForkJoinTask.reportExecutionException(ForkJoinTask.java:605)
        at java.base/java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:981)
        at com.github.pemistahl.lingua.api.LanguageDetector.computeLanguageConfidenceValues(LanguageDetector.kt:160)
        at com.github.pemistahl.lingua.api.LanguageDetector.detectLanguageOf(LanguageDetector.kt:72)
        at com.github.pemistahl.lingua.app.AppKt.runApp(App.kt:153)
        at com.github.pemistahl.lingua.app.AppKt.main(App.kt:27)
        at com.github.pemistahl.lingua.app.AppKt.main(App.kt)
Caused by: java.lang.NoClassDefFoundError
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
        at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:564)
        at java.base/java.util.concurrent.ForkJoinTask.reportExecutionException(ForkJoinTask.java:604)
        ... 6 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.github.pemistahl.lingua.internal.TrainingDataLanguageModel
        at com.github.pemistahl.lingua.api.LanguageDetector$Companion.loadLanguageModel(LanguageDetector.kt:531)
        at com.github.pemistahl.lingua.api.LanguageDetector$Companion.loadLanguageModels(LanguageDetector.kt:520)
        at com.github.pemistahl.lingua.api.LanguageDetector$Companion.access$loadLanguageModels(LanguageDetector.kt:501)
        at com.github.pemistahl.lingua.api.LanguageDetector.lookUpNgramProbability-as5wtIs$lingua(LanguageDetector.kt:467)
        at com.github.pemistahl.lingua.api.LanguageDetector.computeSumOfNgramProbabilities$lingua(LanguageDetector.kt:442)
        at com.github.pemistahl.lingua.api.LanguageDetector.computeLanguageProbabilities$lingua(LanguageDetector.kt:429)
        at com.github.pemistahl.lingua.api.LanguageDetector.computeLanguageConfidenceValues$lambda-4$lambda-3(LanguageDetector.kt:142)
        at java.base/java.util.concurrent.ForkJoinTask$AdaptedInterruptibleCallable.exec(ForkJoinTask.java:1461)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

The NoClassDefFoundError here is not the underlying issue; it is an aftereffect of the original exception which most likely occurred in a different worker thread. The original exception can be seen when manually trying to load the failing class:

Class.forName("com.github.pemistahl.lingua.internal.TrainingDataLanguageModel")
Exception in thread "main" java.lang.AssertionError: Built-in class shadow.kotlin.Any is not found
	at shadow.kotlin.reflect.jvm.internal.impl.builtins.KotlinBuiltIns$3.invoke(KotlinBuiltIns.java:93)
	at shadow.kotlin.reflect.jvm.internal.impl.builtins.KotlinBuiltIns$3.invoke(KotlinBuiltIns.java:88)
	at shadow.kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:578)
	at shadow.kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:651)
	at shadow.kotlin.reflect.jvm.internal.impl.builtins.KotlinBuiltIns.getBuiltInClassByName(KotlinBuiltIns.java:223)
	at shadow.kotlin.reflect.jvm.internal.impl.builtins.KotlinBuiltIns.getAny(KotlinBuiltIns.java:228)
	at shadow.kotlin.reflect.jvm.internal.impl.builtins.KotlinBuiltIns.getAnyType(KotlinBuiltIns.java:498)
	at shadow.kotlin.reflect.jvm.internal.impl.builtins.KotlinBuiltIns.getNullableAnyType(KotlinBuiltIns.java:503)
	at shadow.kotlin.reflect.jvm.internal.impl.builtins.KotlinBuiltIns.getDefaultBound(KotlinBuiltIns.java:508)
	at shadow.kotlin.reflect.jvm.internal.impl.descriptors.impl.TypeParameterDescriptorImpl.createWithDefaultBound(TypeParameterDescriptorImpl.java:56)
	at shadow.kotlin.reflect.jvm.internal.impl.descriptors.NotFoundClasses$MockClassDescriptor.<init>(NotFoundClasses.kt:56)
	at shadow.kotlin.reflect.jvm.internal.impl.descriptors.NotFoundClasses$classes$1.invoke(NotFoundClasses.kt:45)
	at shadow.kotlin.reflect.jvm.internal.impl.descriptors.NotFoundClasses$classes$1.invoke(NotFoundClasses.kt:33)
	at shadow.kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:578)
	at shadow.kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:651)
	at shadow.kotlin.reflect.jvm.internal.impl.descriptors.NotFoundClasses.getClass(NotFoundClasses.kt:97)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.TypeDeserializer.typeConstructor$notFoundClass(TypeDeserializer.kt:136)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.TypeDeserializer.typeConstructor(TypeDeserializer.kt:141)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.TypeDeserializer.simpleType(TypeDeserializer.kt:79)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.TypeDeserializer.type(TypeDeserializer.kt:67)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.MemberDeserializer.valueParameters(MemberDeserializer.kt:332)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.MemberDeserializer.loadConstructor(MemberDeserializer.kt:268)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor.computePrimaryConstructor(DeserializedClassDescriptor.kt:126)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor.access$computePrimaryConstructor(DeserializedClassDescriptor.kt:33)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$primaryConstructor$1.invoke(DeserializedClassDescriptor.kt:64)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$primaryConstructor$1.invoke(DeserializedClassDescriptor.kt:64)
	at shadow.kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:408)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor.getUnsubstitutedPrimaryConstructor(DeserializedClassDescriptor.kt:130)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor.computeConstructors(DeserializedClassDescriptor.kt:133)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor.access$computeConstructors(DeserializedClassDescriptor.kt:33)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$constructors$1.invoke(DeserializedClassDescriptor.kt:65)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$constructors$1.invoke(DeserializedClassDescriptor.kt:65)
	at shadow.kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:408)
	at shadow.kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(LockBasedStorageManager.java:527)
	at shadow.kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor.getConstructors(DeserializedClassDescriptor.kt:141)
	at shadow.kotlin.reflect.jvm.internal.KClassImpl.getConstructorDescriptors(KClassImpl.kt:203)
	at shadow.kotlin.reflect.jvm.internal.KClassImpl$Data$constructors$2.invoke(KClassImpl.kt:94)
	at shadow.kotlin.reflect.jvm.internal.KClassImpl$Data$constructors$2.invoke(KClassImpl.kt:93)
	at shadow.kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(ReflectProperties.java:93)
	at shadow.kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:32)
	at shadow.kotlin.reflect.jvm.internal.KClassImpl$Data.getConstructors(KClassImpl.kt:93)
	at shadow.kotlin.reflect.jvm.internal.KClassImpl.getConstructors(KClassImpl.kt:238)
	at shadow.kotlin.reflect.full.KClasses.getPrimaryConstructor(KClasses.kt:36)
	at shadow.com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory.create(KotlinJsonAdapter.kt:228)
	at shadow.com.squareup.moshi.Moshi.adapter(Moshi.java:146)
	at shadow.com.squareup.moshi.Moshi.adapter(Moshi.java:106)
	at shadow.com.squareup.moshi.Moshi.adapter(Moshi.java:80)
	at com.github.pemistahl.lingua.internal.TrainingDataLanguageModel.<clinit>(TrainingDataLanguageModel.kt:54)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:375)
	at MainKt.main(Main.kt:13)

There are a few reports about AssertionError: Built-in class kotlin.Any is not found, but I am not sure if they completely apply here, because it looks like here the relocation of the packages might be related to this issue.

Reproduction steps

  1. Download lingua-1.2.1-with-dependencies.jar
  2. Run
    java -jar ./lingua-1.2.1-with-dependencies.jar
    
    (I am using Java 17 on Windows, but I am not sure if that makes a difference)
  3. Select "2: all supported languages"
  4. Enter any short text, such as "test"
@pemistahl pemistahl added the bug Something isn't working label Aug 2, 2022
@pemistahl pemistahl added this to the Lingua 1.2.2 milestone Aug 2, 2022
@pemistahl
Copy link
Owner

Hi @Marcono1234, I was able to reproduce this bug. Its cause is the Moshi JSON serialization library that I introduced in Lingua 1.2. The library contains some weird bug. Previously, I initialized the json adapter in the companion object of the TrainingDataLanguageModel. When I move the initialization of the adapter to the top level, everything works fine again. I think I will open a bug report for Moshi because this is certainly weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants