Skip to content

Conversation

@PaintNinja
Copy link
Contributor

Enhances #85 to support also checking the permitted subclasses when running on Java 17+ and the event type is sealed.

For example:

sealed class MouseButtonEvent extends Event {
    final class LeftClick extends MouseButtonEvent {}
    final class RightClick extends MouseButtonEvent {}
}

Previously, we could not apply this optimisation to listeners of MouseButtonEvent because checking the permitted subclasses was not supported, but with this PR we now can as long as we're running on Java 17+.

Enhances MinecraftForge#85 to support also checking the permitted subclasses when running on Java 17+ and the event type is sealed.
@PaintNinja PaintNinja added the enhancement New feature or request label Oct 12, 2025
@Jonathing
Copy link
Member

If you are interested in making EventBus 6 Multi-Release, see my setup for Download Utils, using dedicated projects to aid in Eclipse compatibility.

@PaintNinja
Copy link
Contributor Author

I'm not sure if legacy SecureJarHandler properly supports MR jars, so I took the safe approach of reflection for this one method.

@Jonathing
Copy link
Member

Roger. Keep in mind that I plan on updating ModLauncher and SecureModules on those older versions at some point.

Although, it will be a bit of a challenge as I'll need to update all dependencies that rely on them. ForgeGradle 6 is not too fond of dependency namespace changes, as it only information the consumer of dependencies via a POM file, which fails to take into account dependency capabilities.

.findVirtual(Class.class, "getPermittedSubclasses", methodType)
.asType(methodType.insertParameterTypes(0, Class.class));
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, if possible, add a message stating that you tried to grab the permitted subclasses here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently looks like:

Exception in thread "main" java.lang.ExceptionInInitializerError
	at Scratch.<clinit>(scratch_10.java:17)
Caused by: java.lang.NoSuchMethodException: no such method: java.lang.Class.getPermittedSubclasses()Class[]/invokeVirtual
	at java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:976)
	at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1117)
	at java.base/java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:3649)
	at java.base/java.lang.invoke.MethodHandles$Lookup.findVirtual(MethodHandles.java:2680)
	at Scratch.<clinit>(scratch_10.java:14)
Caused by: java.lang.NoSuchMethodError: 'java.lang.Class[] java.lang.Class.getPermittedSubclasses()'
	at java.base/java.lang.invoke.MethodHandleNatives.resolve(Native Method)
	at java.base/java.lang.invoke.MemberName$Factory.resolve(MemberName.java:1085)
	at java.base/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1114)
	... 3 more

Would you like me to add a message anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because it's not initially clear that it is EventBus 6 that is requesting this member.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants