Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added retrolambda.javaHacks configuration option #143

Merged
merged 3 commits into from
Aug 14, 2018
Merged

Added retrolambda.javaHacks configuration option #143

merged 3 commits into from
Aug 14, 2018

Conversation

lyubomyr-shaydariv
Copy link
Contributor

@lyubomyr-shaydariv lyubomyr-shaydariv commented Aug 12, 2018

In some cases javac may produce incorrect but executable byte code that cannot be translated with ASM therefore making class downgrade impossible. This pull request enables:

  • -Dretrolambda.javacHacks support for the tool
  • <javaHacks> support for the Maven plugin

I could downgrade the code using a patched 2.5.5-SNAPSHOT version and the downgraded code seems to work correctly. The option name javaHacks is a possible subject to change or rename. For example, enabling the key will allow to downgrade the following code that cannot be processed with Retrolambda 2.5.4:

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.util.function.Consumer;

@SuppressWarnings("all")
final class JavacBug
                implements Consumer<Iterable<?>> {

        @Target(ElementType.TYPE_USE)
        @interface A {
        }

        @Override
        public void accept(final Iterable<?> t) {
                final @A Object o = null;
                assert o != null;
        }

}

As of Retrolambda 2.5.4 the code above fails with even for the latest JDK 1.8 javac (1.8.0_181):

java.lang.RuntimeException: Failed to backport class: JavaBug
	at net.orfjackal.retrolambda.Transformers.transform(Transformers.java:129)
	at net.orfjackal.retrolambda.Transformers.transform(Transformers.java:107)
	at net.orfjackal.retrolambda.Transformers.backportClass(Transformers.java:47)
	at net.orfjackal.retrolambda.Retrolambda.run(Retrolambda.java:92)
	at net.orfjackal.retrolambda.Main.main(Main.java:28)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 21
	at net.orfjackal.retrolambda.asm.ClassReader.readLabel(ClassReader.java:2251)
	at net.orfjackal.retrolambda.asm.ClassReader.readTypeAnnotations(ClassReader.java:1678)
	at net.orfjackal.retrolambda.asm.ClassReader.readCode(ClassReader.java:1210)
	at net.orfjackal.retrolambda.asm.ClassReader.readMethod(ClassReader.java:1032)
	at net.orfjackal.retrolambda.asm.ClassReader.accept(ClassReader.java:708)
	at net.orfjackal.retrolambda.asm.ClassReader.accept(ClassReader.java:521)
	at net.orfjackal.retrolambda.Transformers.lambda$transform$4(Transformers.java:107)
	at net.orfjackal.retrolambda.Transformers.transform(Transformers.java:125)

Please note that JDK 1.8 may be a must, for example when using tools like Checker Framework. Please see https://gitlab.ow2.org/asm/asm/issues/317845 for more details.

@lyubomyr-shaydariv lyubomyr-shaydariv changed the title Added retrolambda.javaHacks configuration option. Added retrolambda.javaHacks configuration option Aug 12, 2018
@luontola luontola merged commit 8fae5c8 into luontola:master Aug 14, 2018
@luontola
Copy link
Owner

Thanks. This has been released in Retrolambda 2.5.5.

@lyubomyr-shaydariv lyubomyr-shaydariv deleted the javac-bug branch August 15, 2018 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants