TravaOpenJDK/trava-jdk-11-dcevm

Lambda redefinition ClassCastException when implementing an inner interface

Closed this issue · 1 comments

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

This issue was also submitted to dcevm/dcevm#178


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) {
		
		System.getProperties().entrySet().stream().forEach(e->System.out.println(e));
		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
java.runtime.name=OpenJDK Runtime Environment
java.runtime.version=11.0.5+5-201912121506

The error message is
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.hotswap.agent.util.ReflectionHelper (file:/C:/Jdk/jdk-11-dcevm/lib/hotswap/hotswap-agent.jar) to method com.sun.beans.util.Cache.clear()
WARNING: Please consider reporting this to the maintainers of org.hotswap.agent.util.ReflectionHelper
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "main" java.lang.ClassCastException: class TestDCEVM$Loader$$Lambda$42/0x0000000800138040 cannot be cast to class TestDCEVM$Loader (TestDCEVM$Loader$$Lambda$42/0x0000000800138040 and TestDCEVM$Loader are in unnamed module of loader 'app')
at TestDCEVM.main(TestDCEVM.java:26)

Refactoring the Loader into its own file resolves the issue.

There is new improved lambda support in v11.0.7, should be fixed

https://github.com/TravaOpenJDK/trava-jdk-11-dcevm/releases/tag/dcevm-11.0.7%2B1

This problem is also in dcevm8