bjornharrtell / jts2geojson

JTS from/to GeoJSON converter for Java
MIT License
138 stars 56 forks source link

Error: cannot access Feature/Bad class file error #42

Closed alvindizon closed 3 years ago

alvindizon commented 3 years ago

For our Android app, on upgrade to version 0.16.0, our lint check encountered this error:

error: cannot access Feature
    org.wololo.geojson.Feature[] $this$get, @org.jetbrains.annotations.NotNull()

  bad class file: /Users/../transforms-2/files-2.1/10e0c2a8959b26604a54ebc45767ffff/jetified-jts2geojson-0.16.0.jar(org/wololo/geojson/Feature.class)
    class file has wrong version 55.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.

This is a snippet of the generated java file that was pointed to by the logs (edited to hide details):

import java.lang.System;

@kotlin.Metadata(mv = {1, 4, 2}, bv = {1, 0, 3}, k = 2, d1 = ....)
public final class GeoJsonExtensionsKt {
    ...

    @org.jetbrains.annotations.NotNull()
    public static final org.wololo.geojson.Feature[] get(@org.jetbrains.annotations.NotNull()
    org.wololo.geojson.Feature[] $this$get, @org.jetbrains.annotations.NotNull()
    java.lang.String propName, @org.jetbrains.annotations.NotNull()
    java.lang.String propValue) {
        return null;
    }

....

Not sure how to approach this, your input on what's happening would be much appreciated. Thanks

bjornharrtell commented 3 years ago

The problem is that the compiled artifacts are at Java 11 level (version 55). I don't know why that happens because I've specified I want Java 8 level at https://github.com/bjornharrtell/jts2geojson/blob/b305a757b2a67c34286560e501bab763fd4c9c43/pom.xml#L86-L87.

I have no interest in Java 8 compat myself but contributions are welcome.

alvindizon commented 3 years ago

I've tried the following:

  1. Check out this repo and build JAR using Java 11. Lint check error
  2. Check out this repo and build JAR using Java 8. Lint check passes with generated JAR
  3. Using compiled JAR at Java 11 level, I configured Android Studio to use JDK 11 instead of the built-in JDK 8. Lint check passes but unit tests break with the following error:
    java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JavaType
    ...
    ...
    Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JavaType
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)

    This occurs at a line where GeoJSONFactory.create(jsonString) as FeatureCollection is used.

bjornharrtell commented 3 years ago

@alvindizon does it work with no 2?

It should be possible to produce a Java 8 class level with Java 11 and that is actually the expected result with current pom.xml but must be something wrong with it.

alvindizon commented 3 years ago

Hi @bjornharrtell , with #2, all checks passed but haven't really tested in-app to see if it works normally, but I'd expect it to work fine. Regarding the pom.xml, I agree that the current config should be enough, but I'm still investigating why it produces an incompatible artifact. Since maven-compiler-plugin is version 3.8.1 I've tried to use <release> instead of <source> and <target> but didn't work as well:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <release>8</release>
    </configuration>
</plugin>
alvindizon commented 3 years ago

I rolled back to a previous release and checked out v0.14.3 (commit aed4ba4), and tried to generate a JAR using Java 11--I generated a JAR that produces the same Bad class file error. Could it be that you used Java 8 previously when releasing 0.14.3 and switched to Java 11 in your machine?

bjornharrtell commented 3 years ago

@alvindizon yes many years ago I used Java 8. :P

roryodonnell commented 3 years ago

I'm also experiencing this issue - I will provide an update once I have more info

bjornharrtell commented 3 years ago

Looks like https://github.com/bjornharrtell/jts2geojson/commit/d9ea8827c0db2e0a8897fcaa04e57503e3654876 helps. Dont ask me why... but I'll cut a new release in a few hours.

roryodonnell commented 3 years ago

super - thanks for the rapid response - most likely a travis/devop-sy issue

alvindizon commented 3 years ago

Just checked out 0.16.1 and the bad class file error encountered in our lint check has gone away, however unit tests throw a different error (NoClassDefFoundError: com/fasterxml/jackson/databind/JavaType) but that's not related to this issue, so I'm closing this issue now. Thanks @bjornharrtell