Skip to content

Make reflective call to Lookup lazy on first default method invocation #3448

@Dragas

Description

@Dragas

After moving my project to fully support JPMS (JDK11), and retrofit has become unusable due to the following error:

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make private java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int) accessible: module java.base does not "opens java.lang.invoke" to module retrofit2
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:340)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:280)
	at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:189)
	at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:182)
	at [email protected]/retrofit2.Platform.<init>(Platform.java:59)
	at [email protected]/retrofit2.Platform.findPlatform(Platform.java:44)
	at [email protected]/retrofit2.Platform.<clinit>(Platform.java:35)
	... 11 more

It seems that retrofit deeply depends on Java's Lookup class and making its constructor visible to itself. The issue becomes apparent, when using the JPMS. A workaround for this is to add --add-opens java.base/java.lang.invoke=retrofit2 but it would be nice if there wasn't such need to expose the base module's packages myself. Perhaps add a call to Module#addOpen(String, Module) when initializing retrofit's class?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions