konsoletyper / teavm-flavour

Framework for writing client-side applications using TeaVM
Apache License 2.0
110 stars 19 forks source link

Flavour JSON is not working with Java 17 #72

Closed Ihromant closed 1 year ago

Ihromant commented 2 years ago

I'm using flavour in m project for JSON serialization/deserialization. When I started using it, it wasn't deprecated. Now it prevents me from upgrading Java 11 -> 17. I tried to build it locally with removing all asm dependencies lower than 9.1, bumped teavm to newest version, nothing helps. When I'm building my project I receive error.

[ERROR] Error calling proxy method org.teavm.flavour.json.JSON.getClassDeserializer(Lorg/teavm/metaprogramming/ReflectClass;)V: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.teavm.metaprogramming.impl.UsageGenerator.emitPermutation(UsageGenerator.java:159)
    at org.teavm.metaprogramming.impl.UsageGenerator.lambda$installProxyEmitter$0(UsageGenerator.java:84)
    at org.teavm.dependency.DependencyAnalyzer.lambda$schedulePropagation$4(DependencyAnalyzer.java:379)
    at org.teavm.dependency.DependencyAnalyzer.processQueue(DependencyAnalyzer.java:646)
    at org.teavm.dependency.DependencyAnalyzer.processDependencies(DependencyAnalyzer.java:683)
    at org.teavm.vm.TeaVM.build(TeaVM.java:379)
    at org.teavm.tooling.TeaVMTool.generate(TeaVMTool.java:447)
    at org.teavm.tooling.builder.InProcessBuildStrategy.build(InProcessBuildStrategy.java:275)
    at org.teavm.maven.TeaVMCompileMojo.executeWithBuilder(TeaVMCompileMojo.java:305)
    at org.teavm.maven.TeaVMCompileMojo.execute(TeaVMCompileMojo.java:254)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Caused by: java.lang.BootstrapMethodError: java.lang.UnsupportedOperationException: PermittedSubclasses requires ASM9
    at org.teavm.flavour.json.emit.GenericTypeProvider.findConstructor(GenericTypeProvider.java:64)
    at org.teavm.flavour.json.emit.GenericTypeProvider.getGenericTypesForConstructor(GenericTypeProvider.java:135)
    at org.teavm.flavour.json.emit.JsonDeserializerEmitter.emitConstructor(JsonDeserializerEmitter.java:392)
    at org.teavm.flavour.json.emit.JsonDeserializerEmitter.lambda$emitClassDeserializer$18(JsonDeserializerEmitter.java:191)
    at org.teavm.flavour.json.emit.JsonDeserializerEmitter.emitSubTypes(JsonDeserializerEmitter.java:296)
    at org.teavm.flavour.json.emit.JsonDeserializerEmitter.lambda$emitClassDeserializer$19(JsonDeserializerEmitter.java:187)
    at org.teavm.metaprogramming.impl.CompositeMethodGenerator.lazy(CompositeMethodGenerator.java:357)
    at org.teavm.metaprogramming.impl.CompositeMethodGenerator.captureValue(CompositeMethodGenerator.java:316)
    at org.teavm.metaprogramming.impl.CompositeMethodGenerator$TemplateSubstitutor.var(CompositeMethodGenerator.java:500)
    at org.teavm.metaprogramming.impl.CompositeMethodGenerator$TemplateSubstitutor.invoke(CompositeMethodGenerator.java:827)
    at org.teavm.model.InstructionReadVisitor.visit(InstructionReadVisitor.java:182)
    at org.teavm.model.instructions.InvokeInstruction.acceptVisitor(InvokeInstruction.java:82)
    at org.teavm.model.BasicBlock.readAllInstructions(BasicBlock.java:314)
    at org.teavm.metaprogramming.impl.CompositeMethodGenerator.addProgram(CompositeMethodGenerator.java:201)
    at org.teavm.metaprogramming.impl.MetaprogrammingImpl.emit(MetaprogrammingImpl.java:93)
    at org.teavm.metaprogramming.impl.MetaprogrammingImpl.lambda$lazy$0(MetaprogrammingImpl.java:110)
    at org.teavm.metaprogramming.impl.CompositeMethodGenerator.lazy(CompositeMethodGenerator.java:357)
    at org.teavm.metaprogramming.impl.CompositeMethodGenerator.captureValue(CompositeMethodGenerator.java:316)
    at org.teavm.metaprogramming.impl.CompositeMethodGenerator$TemplateSubstitutor.var(CompositeMethodGenerator.java:500)
    at org.teavm.metaprogramming.impl.CompositeMethodGenerator$TemplateSubstitutor.invoke(CompositeMethodGenerator.java:827)
    at org.teavm.model.InstructionReadVisitor.visit(InstructionReadVisitor.java:182)
    at org.teavm.model.instructions.InvokeInstruction.acceptVisitor(InvokeInstruction.java:82)
    at org.teavm.model.BasicBlock.readAllInstructions(BasicBlock.java:314)
    at org.teavm.metaprogramming.impl.CompositeMethodGenerator.addProgram(CompositeMethodGenerator.java:201)
    at org.teavm.metaprogramming.impl.MetaprogrammingImpl.exit(MetaprogrammingImpl.java:127)
    at org.teavm.flavour.json.emit.JsonDeserializerEmitter.lambda$emitClassDeserializer$21(JsonDeserializerEmitter.java:199)
    at org.teavm.metaprogramming.impl.MetaprogrammingImpl.proxy(MetaprogrammingImpl.java:304)
    at org.teavm.metaprogramming.impl.MetaprogrammingImpl.proxy(MetaprogrammingImpl.java:242)
    at org.teavm.flavour.json.emit.JsonDeserializerEmitter.emitClassDeserializer(JsonDeserializerEmitter.java:183)
    at org.teavm.flavour.json.emit.JsonDeserializerEmitter.getClassDeserializer(JsonDeserializerEmitter.java:112)
    at org.teavm.flavour.json.JSON.getClassDeserializer(JSON.java:80)
    ... 36 more

Manual serialization-deserialization is not an option as well, I have very big amount of DTOs and writing code for it manually is long and error-prone. This issue is related to https://github.com/konsoletyper/teavm/issues/622 where I tried to start writing own serializer prototype, but also didn't succeed.

Ihromant commented 2 years ago

Also because flavour is obviously deprecated, it would be great to remove documentation about it from teavm.org as it's a trap for newcomers like me.

ScraM-Team commented 2 years ago

I think Flavour should work with Java 17+ once the ASM support is upgraded, which looks like it happened in this commit: https://github.com/konsoletyper/teavm/commit/d097350787e6ff1c9434db0fa773adcefc4c1421

If you try out that commit (looks like you'll have to build it yourself until the dev release is posted), please let us know how it works. I haven't tried it yet.

FYI, I'm continuing to improve and upgrade Flavour, see Flavour Plus here: https://frequal.com/FlavourPlus/

Ihromant commented 2 years ago

I rebuilt jar to SNAPSHOT from source with bumped teavm version to the latest. It didn't help at all (or maybe I did something wrong). Will try with your jars, will notify about the results.

Ihromant commented 2 years ago

Just checked, same error.

ScraM-Team commented 2 years ago

OK, will check later today.

konsoletyper commented 2 years ago

Also because flavour is obviously deprecated, it would be great to remove documentation about it from teavm.org as it's a trap for newcomers like me.

Flavour it not deprecated, it's suspended for an upredictable time. However, it's under Apache license, which means you can fork code and modify WRT you needs.

As for Java 17, Flavour uses ASM by itself, not the one provided by TeaVM, so you can get Flavour source code, update ASM version there and build it locally.

As for site issue, yes, I know, but removing mentions of Flavour requires to make decisions like how to restructure the whole site, and for this I have no time.

ScraM-Team commented 2 years ago

Sorry for the delay, I have been under the weather.

For me, the latest TeaVM, compiled with Java 17 is able to build the Flavour archetype app (from Docs/Getting Started) with 4 changes to the POM file, shown below. I will try a JSON deserialization test later to see if it has a problem

Java version: < 17</java.version>

<java.version>1.8</java.version>

TeaVM Version: < 0.7.0-SNAPSHOT</teavm.version>

<teavm.version>0.6.1</teavm.version>

Maven compiler plugin version: < 3.10.1

    <version>3.1</version>

Maven war plugin version < 3.3.2

    <version>2.4</version>
ScraM-Team commented 2 years ago

I tried the JSON ser / deser sample code from https://teavm.org/docs/flavour/json.html

It seems to compile fine using the above POM changes with a Java17-compiled TeaVM (from the latest sources).

Let us know if you're still getting errors with Java17. If it would help I could post my sample project.

Ihromant commented 2 years ago

After long investigation I resolved issue locally. Way to resolve it:

  1. Rebuild whole teavm with updated plugins under java 17 (pull request for it will point to this issue).
  2. Rebuild whole flavour with teavm-0.7.0-SNAPSHOT under 17 java.
  3. Rebuild my own project with teavm-0.7.0-SNAPSHOT (built under 17) and flavour 0.3.0-SNAPSHOT (built under 17).

If you replace during build of flavour 0.7.0-SNAPSHOT to 0.7.0-dev-1207 - then at least on my machine I am able to reproduce error above on example project (same failure during mvn clean install -DskipTests). I don't know whether it's because 0.7.0-dev-1207 doesn't contain required fixes or if you are using Flavour with Java 17 - you need all bytecode to be built using 17, but fact is fact.

Ihromant commented 2 years ago

Funny update: teavm plugin in IDEA continues throwing same error (probably due to the fact that it was built under Java 8).

Ihromant commented 1 year ago

Issue was resolved for me with migration 0.7.0-dev-1207 -> 0.7.0-dev-1209 for both teavm and plugin. Don't know what fixed that, my updates for plugins or some internal changes, but it works. Many thanks anyway. @konsoletyper @ScraM-Team