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

Make Types#isLambdaType work on JDK >= 21 #349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

toby1984
Copy link

Hi,

After upgrading our application to JDK 21 (Eclipse Temurin) we noticed that serialization was suddenly crashing. An investigation of the generated XML showed that lambda types were no longer being detected correctly (see screenshot, jdk-17 on LHS, jdk-21 on RHS)

image

I traced this down to https://bugs.openjdk.org/browse/JDK-8254979 and the code in Types#isLambdaType which only checks Class#getSimpleName.

When trying to execute the tests in LambdaTest.java I realized that at least JDK 21 (Eclipse Temurin) now also generated slightly different classnames for the lambdas in that unit test so I also adjusted the regular expression in Types#isLambdaType to be a bit more fuzzy... looking at https://stackoverflow.com/questions/23870478/how-to-correctly-determine-that-an-object-is-a-lambda , Brian Goetz would not approve of this code anyway ;)

Last but not least, JDK21 uses a different "implMethodKind" value in one case that made a unit test fail so I extended the normalizeLambda() method in LambdaTests.java with another hack.

@toby1984
Copy link
Author

Just realized that my PR has gone uncommented/unmerged since October 2023 ... is XStream still being maintained ? I see tons of forks but no new releases since December 2022.

@joehni
Copy link
Member

joehni commented Feb 13, 2024

Not unmaintained, but my time spare for OSS development was mostly occupied by real world probems.

@toby1984
Copy link
Author

No worries, your effort is much appreciated! I was just checking whether I could maybe drop my own XStream fork (which has this patch applied) and use a current release instead. Any chance getting this PR merged so I could use this repo again ?

@govindbalaji-s
Copy link

Hi @toby1984 , I couldn't find any fix for https://bugs.openjdk.org/browse/JDK-8254979 merged or any related changes at https://github.com/openjdk/jdk/commits/master/src/java.base/share/classes/java/lang/Class.java. Locally, I still get isSimpleName() returning non-empty for lambdas and method references with JDK21 and JDK17. Would the changes to the regex pattern alone suffice then?


public static final boolean isLambdaType(final Class<?> type) {
return type != null && type.isSynthetic() && lambdaPattern.matcher(type.getSimpleName()).matches();
if (type != null && type.isSynthetic()) {

Choose a reason for hiding this comment

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

Ah the "fix" for https://bugs.openjdk.org/browse/JDK-8254979 was just change in documentation. So I think we don't need to handle Class.isSimpleName() returning empty then.

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

Successfully merging this pull request may close these issues.

None yet

3 participants