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

java.lang.NoClassDefFoundError: kotlin/KotlinNothingValueException #89

Closed
piyusht007 opened this issue Feb 15, 2021 · 7 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@piyusht007
Copy link

Hi,

I am trying to use Lingua inside a plain Java maven project and using following maven dependency for that:

<dependency>
                <groupId>com.github.pemistahl</groupId>
                <artifactId>lingua</artifactId>
                <version>1.0.3</version>
</dependency>

Code Sample:

import com.github.pemistahl.lingua.api.Language;
import com.github.pemistahl.lingua.api.LanguageDetector;
import com.github.pemistahl.lingua.api.LanguageDetectorBuilder;

import static com.github.pemistahl.lingua.api.Language.*;

public class Test {
    public static void detect(){
        LanguageDetector detector = LanguageDetectorBuilder.fromLanguages(ENGLISH, FRENCH, GERMAN, SPANISH).build();
        Language language = detector.detectLanguageOf("languages are awesome");
        System.out.println(language);
    }

    public static void main(String[] args) {
        detect();
    }
}

While running I am getting following exception:

Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/KotlinNothingValueException
	at kotlinx.serialization.SerializersKt.serializer(Unknown Source)
	at com.github.pemistahl.lingua.internal.TrainingDataLanguageModel$Companion.fromJson(TrainingDataLanguageModel.kt:150)
	at com.github.pemistahl.lingua.api.LanguageDetector.loadLanguageModel$lingua(LanguageDetector.kt:401)
	at com.github.pemistahl.lingua.api.LanguageDetector$loadLanguageModels$1.invoke(LanguageDetector.kt:407)
	at com.github.pemistahl.lingua.api.LanguageDetector$loadLanguageModels$1.invoke(LanguageDetector.kt:79)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at com.github.pemistahl.lingua.api.LanguageDetector.lookUpNgramProbability$lingua(LanguageDetector.kt:390)
	at com.github.pemistahl.lingua.api.LanguageDetector.computeSumOfNgramProbabilities$lingua(LanguageDetector.kt:366)
	at com.github.pemistahl.lingua.api.LanguageDetector.computeLanguageProbabilities$lingua(LanguageDetector.kt:353)
	at com.github.pemistahl.lingua.api.LanguageDetector.computeLanguageConfidenceValues(LanguageDetector.kt:162)
	at com.github.pemistahl.lingua.api.LanguageDetector.detectLanguageOf(LanguageDetector.kt:102)
	at com.tomtom.ssv.apt.ingestion.service.LanguageDetector.detect(LanguageDetector.java:67)
	at com.tomtom.ssv.apt.ingestion.service.LanguageDetector.main(LanguageDetector.java:72)
Caused by: java.lang.ClassNotFoundException: kotlin.KotlinNothingValueException
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 13 more
@pemistahl
Copy link
Owner

pemistahl commented Feb 15, 2021

Hi @piyusht007,

this obviously resembles the problem stated in #88. The cause of this problem most likely is the kotlinx-serialization library which Lingua uses as a dependency for (de)serializing the language models. According to their issue tracker, that library has too many bugs. In the long term, I will switch to another json serialization library, probably Jackson. Thanks for your code sample, now I can try to reproduce the problem on my machine and fix it, perhaps even with keeping kotlinx-serialization.

Can you please tell me which JDK (vendor and version) you are using? This might be essential for reproducing the problem. Thanks.

@pemistahl pemistahl added the bug Something isn't working label Feb 15, 2021
@pemistahl pemistahl added this to the Lingua 1.1.0 milestone Feb 15, 2021
@piyusht007
Copy link
Author

piyusht007 commented Feb 15, 2021

Hi @pemistahl , Following is the JDK version:

java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
  • Vendor: Oracle Corporation

@ahnqirage
Copy link

Hi @piyusht007 , I also encountered the same problem. After I changed the maven dependency, it worked

    <dependency>
        <groupId>com.github.pemistahl</groupId>
        <artifactId>lingua</artifactId>
        <version>1.0.3</version>

        <exclusions>
            <exclusion>
                <artifactId>kotlin-stdlib</artifactId>
                <groupId>org.jetbrains.kotlin</groupId>
            </exclusion>
            <exclusion>
                <artifactId>kotlin-stdlib-common</artifactId>
                <groupId>org.jetbrains.kotlin</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8 -->
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>1.4.10</version>
    </dependency>
    <dependency>
        <artifactId>kotlin-stdlib-common</artifactId>
        <groupId>org.jetbrains.kotlin</groupId>
        <version>1.4.10</version>
    </dependency>

@pemistahl
Copy link
Owner

@ahnqirage This is weird because the release notes for Kotlin 1.4 say that it is not necessary anymore to set the dependency for the Kotlin standard library explicitly. I have not been able so far to reproduce the problem on my machine.

I will update all dependencies for the next Lingua release including the Kotlin compiler. I hope that the problem will be solved then. I will need some more time for it though. Please stay tuned.

@ahnqirage
Copy link

@ahnqirage This is weird because the release notes for Kotlin 1.4 say that it is not necessary anymore to set the dependency for the Kotlin standard library explicitly. I have not been able so far to reproduce the problem on my machine.

I will update all dependencies for the next Lingua release including the Kotlin compiler. I hope that the problem will be solved then. I will need some more time for it though. Please stay tuned.

I'm working with springboot.
I found a default value “<kotlin.version>1.2.71</kotlin.version>” in "spring-boot-dependencies-2.1.4.RELEASE.pom".
After explicitly naming version "<kotlin.version>1.4.10</kotlin.version>" in the boot pom, it works without modifying lingua dependency.
It may be the user's problem?

@pemistahl
Copy link
Owner

pemistahl commented Mar 9, 2021

It may be the user's problem?

I think you are right but it's not the user's deliberate fault. The explicitly set Kotlin version in Spring Boot seems to overwrite the implicit Kotlin 1.4 dependency. But the user is not able to know about this because the error message is so unspecific.

I will simply add the explicit dependency to Kotlin 1.4 again in the next Lingua release. This should fix it once and for all. Thanks for your help @ahnqirage. Without you, I would not have found the cause so quickly.

@pemistahl
Copy link
Owner

I hope that I've fixed this now.

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

3 participants