HotswapProjects / openjdk-jdk11u-dcevm

Dcevm11 sources, binaries are available at https://travis-ci.org/TravaOpenJDK/trava-jdk-11-dcevm
GNU General Public License v2.0
30 stars 10 forks source link

Lambda redefinition ClassCastException when implementing an inner interface #5

Closed samgabriel closed 4 years ago

samgabriel commented 4 years ago

I am not sure if this is the right place but this could be a duplicate of another issue that i filed on the dcevm repository. That is the link to the issue issue for reference https://github.com/dcevm/dcevm/issues/178

The following code always fails when any part of the class is changed even if no changes happen to the actual interface.

import java.util.HashMap;

public class TestDCEVM {
    public static class Context {
    }

    @FunctionalInterface
    interface Loader {
        void load(Context context);

        static Loader DEFAULT = context -> {
            System.out.println("context");
        };
    }

    public static void main(String[] args) {

        while (true) {

            HashMap map = new HashMap();
            map.put("loader", Loader.DEFAULT);
            // The line below will cause a ClassCastException any time the class
            // is changed.
            Loader loader = (Loader) map.get("loader");
            loader.load(new Context());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                break;
            }
        }
    }
}

This is running with the latest build both in jdk 11 and jdk 8

The error message is Exception in thread "main" java.lang.ClassCastException: TestDCEVM$Loader$$Lambda$1/902919927 cannot be cast to TestDCEVM$Loader at TestDCEVM.main(TestDCEVM.java:24)

Refactoring the Loader into its own file resolves the issue.

skybber commented 4 years ago

fixed in last v11.0.7+1 https://github.com/TravaOpenJDK/trava-jdk-11-dcevm/releases/tag/dcevm-11.0.7%2B1