Status Update
Comments
cr...@gmail.com <cr...@gmail.com> #2
Jake Wharton makes an excellent point on why this should be implemented in his blog: https://jakewharton.com/androids-java-9-10-11-and-12-support/
All Java 12 language features are implemented as part of the Java compiler without any new bytecodes or APIs. These features (expression switch and string literals) are rather nice. However, in order to support Java 12, we'll need to support Java 11, and in order to do that, we'll need this feature.
All Java 12 language features are implemented as part of the Java compiler without any new bytecodes or APIs. These features (expression switch and string literals) are rather nice. However, in order to support Java 12, we'll need to support Java 11, and in order to do that, we'll need this feature.
ag...@google.com <ag...@google.com>
ki...@gmail.com <ki...@gmail.com> #3
It would seem to me that unless this is implemented there is going to be trouble ahead for developers !!
cj...@gmail.com <cj...@gmail.com> #5
I see the linked duplicate issue is fixed. Is this one also fixed too?
ze...@google.com <ze...@google.com> #6
Yes. D8 (and R8) now support desugaring nest-based access. It requires (as desugaring generally does) that you specify the full classpath/program as part of compilation so that the compiler has access to the full set of members in a nest. Since very few D8/R8 users are compiling Java 11 code there could be issues that pop up. If you hit any, don't hesitate to file an issue in our D8 component!
Description
Ideally D8 would desugar these nestmates. A simple strategy would be falling back to pre-Java 11 behavior of generating a synthetic accessor method (which R8 could then remove, if enabled) for each access across the nest.
Repro:
$ java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
$ java -jar ~/dev/android/r8/build/libs/d8.jar --version
D8 1.3.22-dev
build engineering
$ cat Java11.java
import java.util.function.*;
class Java11 {
private final String name;
Java11(String name) {
}
private final class Inner implements Runnable {
@Override public void run() {
System.out.println(name); // <-- private member across class boundary
}
}
public static void main(String... args) {
new Java11("Test").new Inner().run();
}
}
$ javac Java11.java
$ java -jar /Users/jakew/dev/android/r8/build/libs/d8.jar --lib $ANDROID_HOME/platforms/android-28/android.jar --release --output . *.class
Compilation failed with an internal error.
java.lang.UnsupportedOperationException
at com.android.tools.r8.org.objectweb.asm.ClassVisitor.visitNestHostExperimental(ClassVisitor.java:158)
at com.android.tools.r8.org.objectweb.asm.ClassReader.accept(ClassReader.java:541)
at com.android.tools.r8.org.objectweb.asm.ClassReader.accept(ClassReader.java:391)
at com.android.tools.r8.graph.JarClassFileReader.read(JarClassFileReader.java:96)
at com.android.tools.r8.dex.ApplicationReader$ClassReader.lambda$readClassSources$1(ApplicationReader.java:231)
at java.base/java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1448)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)