Skip to content

Commit

Permalink
Extract complex expression to help JDK 8 make sense of the Java types
Browse files Browse the repository at this point in the history
Full explanation:
JDK 8 doesn't realize we want to handle a stream of `JApiCompatibility`
elements. Instead, the compiler thinks we want to create a stream of
`JApiHasChangeStatus` elements. So I just extracted the complex
expression to a constant with the appropriate type and it works fine.

Other JDK versions get it right without the type hint. ¯\_(ツ)_/¯

Root cause of the problem:

```
Caused by: java.lang.invoke.LambdaConversionException: Invalid receiver type interface japicmp.model.JApiHasChangeStatus; not a subtype of implementation type interface japicmp.model.JApiCompatibility
	at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:233)
	at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:303)
	at java.lang.invoke.CallSite.makeSite(CallSite.java:302)
	... 54 more
```
  • Loading branch information
guillermocalvo committed Aug 20, 2024
1 parent c4659f1 commit 554a6c6
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ private final String renderCompatibilityChanges(List<? extends JApiCompatibility
}

private String renderAllCompatibilityChanges(JApiClass clazz) {
return renderCompatibilityChanges(Stream.of(
final Stream<List<? extends JApiCompatibility>> allCompatibilityChanges = Stream.of(
singletonList(clazz),
singletonList(clazz.getClassFileFormatVersion()),
singletonList(clazz.getSuperclass()),
Expand All @@ -397,7 +397,8 @@ private String renderAllCompatibilityChanges(JApiClass clazz) {
clazz.getMethods(),
clazz.getMethods().stream().map(JApiMethod::getReturnType).collect(toList()),
clazz.getMethods().stream().map(JApiMethod::getParameters).flatMap(List::stream).collect(toList()),
clazz.getFields())
clazz.getFields());
return renderCompatibilityChanges(allCompatibilityChanges
.flatMap(List::stream)
.map(JApiCompatibility::getCompatibilityChanges)
.flatMap(List::stream)
Expand Down

0 comments on commit 554a6c6

Please sign in to comment.