Skip to content

Commit 1b1c607

Browse files
authored
Merge pull request #106 from JakeWharton/jw/default-package
Support method references to sibling classes in the default package.
2 parents 6fb044f + f0eea0d commit 1b1c607

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright © 2013-2016 Esko Luontola and other Retrolambda contributors
2+
// This software is released under the Apache License 2.0.
3+
// The license text is at http://www.apache.org/licenses/LICENSE-2.0
4+
5+
import org.junit.Test;
6+
7+
public final class DefaultPackageTest {
8+
@Test
9+
public void method_reference_to_sibling_class() {
10+
SiblingClass sibling = new SiblingClass();
11+
Runnable lambda = sibling::method;
12+
lambda.run();
13+
}
14+
}
15+
16+
class SiblingClass {
17+
void method() {
18+
}
19+
}

retrolambda/src/main/java/net/orfjackal/retrolambda/lambdas/BackportLambdaInvocations.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ private boolean isOwnedMethodVisible(Handle implMethod) {
104104
}
105105

106106
private boolean isNonOwnedMethodVisible(Handle implMethod) {
107-
String classPackage = className.substring(0, className.lastIndexOf('/'));
108-
String implPackage = implMethod.getOwner().substring(0, implMethod.getOwner().lastIndexOf('/'));
107+
int classNameLastSlash = className.lastIndexOf('/');
108+
String classPackage = classNameLastSlash == -1 ? "" : className.substring(0, classNameLastSlash);
109+
110+
int implMethodLastSlash = implMethod.getOwner().lastIndexOf('/');
111+
String implPackage = implMethodLastSlash == -1 ? "" : implMethod.getOwner().substring(0, implMethodLastSlash);
112+
109113
if (classPackage.equals(implPackage)) {
110114
return true; // All method visibilities in the same package will be visible.
111115
}

0 commit comments

Comments
 (0)