fury icon indicating copy to clipboard operation
fury copied to clipboard

fix(java): update pom.xml to use javac 8

Open stardustman opened this issue 1 year ago • 8 comments

fix using high version jdk compile to low version such as jdk8 using --release instead of -target solve the https://github.com/apache/incubator-fury/issues/1577

Starting JDK 9, the javac executable can accept the --release option to specify against which Java SE release you want to build the project. For example, you have JDK 11 installed and used by Maven, but you want to build the project against Java 8. The --release option ensures that the code is compiled following the rules of the programming language of the specified release, and that generated classes target the release as well as the public API of that release. This means that, unlike the -source and -target options, the compiler will detect and generate an error when using APIs that don't exist in previous releases of Java SE. https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-release.html

stardustman avatar Apr 26 '24 09:04 stardustman

Hi @stardustman , thanks for your contribution. Could you add a ByteBuffer ut for this ?

chaokunyang avatar Apr 26 '24 09:04 chaokunyang

Hi @stardustman , thanks for your contribution. Could you add a ByteBuffer ut for this ?

Seems this is not easy to add a test, we must compile use one java version, and run it with another java version.

chaokunyang avatar Apr 26 '24 15:04 chaokunyang

this 0.4.1 version in mvnrepository compile with jdk17? or other version?

stardustman avatar Apr 28 '24 03:04 stardustman

this 0.4.1 version in mvnrepository compile with jdk17? or other version?

The major in class file is 52, so it should be java8 already

chaokunyang avatar Apr 28 '24 03:04 chaokunyang

this 0.4.1 version in mvnrepository compile with jdk17? or other version?

The major in class file is 52, so it should be java8 already if this jar was compiled using jdk8's javac to get class file, this should not report error when execute with jdk8. but I get error when I serialize the ByteBuffer, example code like this:

import io.fury.Fury;
import io.fury.ThreadLocalFury;
import io.fury.ThreadSafeFury;
import io.fury.config.Language;

import java.nio.ByteBuffer;

public class FuryTest {


    // Note that Fury instances should be reused between
    // multiple serializations of different objects.
    private static final ThreadSafeFury fury = new ThreadLocalFury(classLoader -> {
        Fury f = Fury.builder()
                .withLanguage(Language.JAVA)
                .withClassLoader(classLoader)
                .requireClassRegistration(false)
                .build();
        return f;
    });

    public static byte[] encoder(Object object) {
        return fury.serialize(object);
    }

    public static <T> T decoder(byte[] bytes) {
        return (T) fury.deserialize(bytes);
    }

    public static void main(String[] args) {
        byte len = 10;
        ByteBuffer byteBuffer = ByteBuffer.allocate(len);
        for (int i = 0; i < len; i++) {
            byteBuffer.put((byte) i);
        }
        byte[] bytes = FuryTest.encoder(byteBuffer);
        System.out.println(bytes.length);

    }

}

stardustman avatar Apr 28 '24 04:04 stardustman

I forgot which javac version I used to release jar.

I use following steps to guess javac version:

  • download jar from https://mvnrepository.com/artifact/org.furyio/fury-core/0.4.1
  • Extract classfile: jar xf fury-core-0.4.1.jar io/fury/Fury.class
  • Get major version: javap -verbose -cp fury-core-0.4.1.jar io/fury/Fury.class | grep "major"

chaokunyang avatar Apr 28 '24 04:04 chaokunyang

I use the branch releases-0.4.1 and jdk1.8.0_241 then execute the mvn package in the IDE to get the final jar file, and test using this jar, this time the test code can execute, but using the jar download from mvn central repo report error. I also try to use jdk11 to execute the mvn package but get the error: package sun.misc does not exist.

stardustman avatar Apr 28 '24 06:04 stardustman