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

Fix lambda inference on openj9 and Java 12 and higher. #66

Merged
merged 6 commits into from
Apr 9, 2021

Conversation

TwilightFlower
Copy link
Contributor

I fixed the problem in my last PR (I feel like I'd fixed that locally and forgot to add it to git, whoops) and also added support for lambda inference on Java 12 and higher by changing the strategy for circumventing access control on those versions.

Nuclearfarts added 3 commits March 13, 2020 14:31
I'm honestly not sure how I missed this error, it's... pretty obvious
now that I look at it. I probably fixed it locally and forgot to commit
or something.
@LexManos
Copy link

Hey, just checking in on this PR, we use this tool in Forge and are running into this issue as well. This change seems to be working. So checking to see if this will be pulled.

Java 14 changed the way the JVM handles varargs internally, meaning that
new Object[] {...} can't be used as a substitute for varargs on Java 6
source level anymore. However, invokeWithArguments explicitly wants an
Object[], so it still works.
@TwilightFlower
Copy link
Contributor Author

(copy-pasting from commit message since people generally don't read those)
Java 14 changed the way the JVM handles varargs internally, meaning that
new Object[] {...} can't be used as a substitute for varargs on Java 6
source level anymore. However, invokeWithArguments explicitly wants an
Object[], so it works fine on Java 14 while still maintaining Java 6 source compatibility.

@naveenchandra91
Copy link

HI @jhalterman : Can we merge this pull request or is there any modifications expected to merge this pull request?

@mkurz
Copy link

mkurz commented Feb 8, 2021

Ping @jhalterman 😉

@artszko
Copy link

artszko commented Feb 23, 2021

Any chances to get this merged in the near future? @jhalterman

@chhsiao90
Copy link

chhsiao90 commented Apr 7, 2021

Hi @Nuclearfarts ,

I just found it should work with MethodHandles.Lookup to get the override setter. I'm not sure if SharedSecrets is needed to support Java 12 and higher. Maybe it's for supporting openj9?

Here is the minimum code which works all java versions between 9 and 15.

Method privateLookupIn = MethodHandles.class.getMethod("privateLookupIn", Class.class, Lookup.class);
Lookup lookup = (Lookup) privateLookupIn.invoke(null, AccessibleObject.class, MethodHandles.lookup());
MethodHandle overrideSetter = lookup.findSetter(AccessibleObject.class, "override", boolean.class);

Class<?> constantPoolClass = Class.forName("jdk.internal.reflect.ConstantPool");
Method getConstantPool = Class.class.getDeclaredMethod("getConstantPool");
overrideSetter.invoke(getConstantPool, true);
Method getConstantPoolSize = constantPoolClass.getDeclaredMethod("getSize");
overrideSetter.invoke(getConstantPoolSize, true);
Method getConstantPoolMethodAt = constantPoolClass.getDeclaredMethod("getMethodAt", int.class);
overrideSetter.invoke(getConstantPoolMethodAt, true);

@chhsiao90
Copy link

I saw the comment #49 (comment)

It's for openj9

@TwilightFlower
Copy link
Contributor Author

quite honestly i'm not looking at this anymore since we've managed to remove most uses of it.

@jhalterman jhalterman merged commit 4218fcb into jhalterman:master Apr 9, 2021
@mkurz
Copy link

mkurz commented Apr 9, 2021

@jhalterman Will you make a new release? Does this also fix #52?

@jhalterman
Copy link
Owner

@mkurz Yes, I just cut a release: 0.6.3. And yes, tests pass on JDK 12 and 14 now, so I've closed #52.

@mkurz
Copy link

mkurz commented Apr 9, 2021

@jhalterman Fantastic, thanks!

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.

8 participants