Skip to content

Commit 2f2e124

Browse files
committed
Fixed a compile error when calling default methods from another module due to the delegate methods being marked synthetic
Fixes #56
1 parent e2156af commit 2f2e124

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ optimizations to that mechanism may break Retrolambda.
208208
Version History
209209
---------------
210210

211+
### Upcoming
212+
213+
- Fixed a compile error when calling default methods from another module
214+
([Issue #56](https://github.com/orfjackal/retrolambda/issues/56))
215+
211216
### Retrolambda 2.0.3 (2015-06-07)
212217

213218
- Fixed Retrolambda generating stack map frames for Java 5 bytecode,

end-to-end-tests/src/main/java/net/orfjackal/retrolambda/test/InMainSources.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2013-2014 Esko Luontola <www.orfjackal.net>
1+
// Copyright © 2013-2015 Esko Luontola <www.orfjackal.net>
22
// This software is released under the Apache License 2.0.
33
// The license text is at http://www.apache.org/licenses/LICENSE-2.0
44

@@ -19,4 +19,20 @@ public static int callLambda() throws Exception {
1919
public static List<String> useLambdaOfImportedType(List<String> items) {
2020
return Lists.transform(items, String::toUpperCase);
2121
}
22+
23+
public interface Interface {
24+
default String defaultMethod() {
25+
return "default";
26+
}
27+
}
28+
29+
public static class Implementer implements Interface {
30+
}
31+
32+
public static class Overrider implements Interface {
33+
@Override
34+
public String defaultMethod() {
35+
return "overridden";
36+
}
37+
}
2238
}

end-to-end-tests/src/test/java/net/orfjackal/retrolambda/test/DefaultMethodsTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ default Callable<String> captureThis() {
472472
*/
473473
@Test
474474
public void default_methods_with_lambdas_in_another_package() throws Exception {
475+
assumeThat(SystemUtils.JAVA_VERSION_FLOAT, is(lessThan(1.8f)));
476+
475477
UsesLambdasInAnotherPackage obj = new UsesLambdasInAnotherPackage() {
476478
};
477479
assertThat(obj.stateless().call(), is("foo"));
@@ -480,6 +482,34 @@ public void default_methods_with_lambdas_in_another_package() throws Exception {
480482
obj.getClass().getDeclaredMethods(), arrayWithSize(2));
481483
}
482484

485+
/**
486+
* Though we use {@link InMainSources}, because the Retrolambda Maven plugin
487+
* processes the main sources separately from the test sources, the effect is
488+
* the same as if they were in another module.
489+
*/
490+
@Test
491+
public void calling_default_methods_from_another_module_through_interface() {
492+
InMainSources.Interface implementer = new InMainSources.Implementer();
493+
assertThat(implementer.defaultMethod(), is("default"));
494+
495+
InMainSources.Interface overrider = new InMainSources.Overrider();
496+
assertThat(overrider.defaultMethod(), is("overridden"));
497+
}
498+
499+
/**
500+
* Fixes issue of the generated delegate methods being marked as synthetic,
501+
* in which case the Java compiler causes "error: cannot find symbol"
502+
* for direct calls to those methods.
503+
*/
504+
@Test
505+
public void calling_default_methods_from_another_module_through_class() {
506+
InMainSources.Implementer implementer = new InMainSources.Implementer();
507+
assertThat(implementer.defaultMethod(), is("default"));
508+
509+
InMainSources.Overrider overrider = new InMainSources.Overrider();
510+
assertThat(overrider.defaultMethod(), is("overridden"));
511+
}
512+
483513

484514
/**
485515
* We're unable to backport default methods if we cannot modify the interface,
@@ -553,7 +583,7 @@ default void annotatedDefaultMethod() {
553583
}
554584

555585
@SomeAnnotation(4)
556-
public static void annotatedStaticMethod() {
586+
static void annotatedStaticMethod() {
557587
}
558588
}
559589

retrolambda/src/main/java/net/orfjackal/retrolambda/interfaces/AddMethodDefaultImplementations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void visit(int version, int access, String name, String signature, String
2929
public void visitEnd() {
3030
for (MethodInfo method : analyzer.getDefaultMethods(Type.getObjectType(className))) {
3131
Bytecode.generateDelegateMethod(cv,
32-
ACC_PUBLIC | ACC_SYNTHETIC,
32+
ACC_PUBLIC,
3333
method.toMethodRef().toHandle(),
3434
method.getDefaultMethodImpl().toHandle());
3535
}

0 commit comments

Comments
 (0)