osglworks / java-tool

Some simple common Java utilities
Apache License 2.0
52 stars 18 forks source link

Java 11: java.lang.NoSuchMethodException: java.lang.String.<init>([C, boolean) #198

Closed raycobd closed 5 years ago

raycobd commented 5 years ago

Here: https://github.com/osglworks/java-tool/blob/master/src/main/java/org/osgl/util/Unsafe.java

static {
        try {
            STRING_BUF = String.class.getDeclaredField("value");
            STRING_BUF.setAccessible(true);
            FASTSTR_BUF = FastStr.class.getDeclaredField("buf");
            FASTSTR_BUF.setAccessible(true);
            char[] ca = new char[0];
            if (.JAVA_VERSION >= 7) {
                SHARED_STR_CONSTRUCTOR = String.class.getDeclaredConstructor(ca.getClass(), Boolean.TYPE);
                SHARED_STR_CONSTRUCTOR.setAccessible(true);
            }

        } catch (NoSuchFieldException var1) {
            throw E.unexpected(var1);
        } catch (NoSuchMethodException var2) {
            throw E.unexpected(var2);
        }
    }

In the line 44:

With Java 11 it is throwing an exception:

SHARED_STR_CONSTRUCTOR = String.class.getDeclaredConstructor(ca.getClass(), Boolean.TYPE);

It seems there is no such constructor for the String class.

greenlaw110 commented 5 years ago

@raycobd osgl-tool is designed to be working on Java7 and Java8, which does not work on Java 11.

The next version of osgl library is planned to work on modern Java however.

Thanks anyway.