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

SnakeYAML requires the java.desktop module #68

Open
fvasco opened this issue Nov 16, 2021 · 1 comment · May be fixed by #83
Open

SnakeYAML requires the java.desktop module #68

fvasco opened this issue Nov 16, 2021 · 1 comment · May be fixed by #83

Comments

@fvasco
Copy link

fvasco commented Nov 16, 2021

The java.desktop is a quite huge dependency for a parser, please consider avoiding this dependency or parse the Yaml at compile time (this improves performances too).

java.lang.NoClassDefFoundError: java/beans/IntrospectionException
        at org.yaml.snakeyaml.representer.BaseRepresenter.getPropertyUtils(BaseRepresenter.java:202)
        at org.yaml.snakeyaml.Yaml.initDumperOptions(Yaml.java:120)
        at org.yaml.snakeyaml.Yaml.<init>(Yaml.java:113)
        at org.yaml.snakeyaml.Yaml.<init>(Yaml.java:103)
        at ua_parser.Parser.initialize(Parser.java:80)
        at ua_parser.Parser.<init>(Parser.java:45)
        ...
Caused by: java.lang.ClassNotFoundException: java.beans.IntrospectionException
        at java.base/java.net.URLClassLoader.findClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 19 common frames omitted
@fvasco
Copy link
Author

fvasco commented Dec 9, 2021

The new snakeyaml-engine loads regexes.yaml successfully and fixes this issue.

Here is a Kotlin POC

import org.snakeyaml.engine.v2.api.Load
import org.snakeyaml.engine.v2.api.LoadSettings
import ua_parser.UserAgentParser

fun main() {
    val load = Load(LoadSettings.builder().build())
    val regexes = UserAgentParser::class.java.getResourceAsStream("/ua_parser/regexes.yaml")!!.use { stream ->
        load.loadFromString(stream.reader().readText()) as Map<String, *>
    }
    println(regexes["user_agent_parsers"])
}
dependencies {
    api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    api 'org.snakeyaml:snakeyaml-engine:2.3'
    api 'com.github.ua-parser:uap-java:1.5.2'
}

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

Successfully merging a pull request may close this issue.

1 participant