Skip to content

Commit 281ef93

Browse files
committed
Do not try backporting java.* classes
Fixes #34
1 parent 0059e93 commit 281ef93

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright © 2013-2014 Esko Luontola <www.orfjackal.net>
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+
package java.lang;
6+
7+
import net.orfjackal.retrolambda.test.ClasspathTest;
8+
9+
/**
10+
* @see ClasspathTest#ignores_classes_in_explicit_classpath_that_are_under_the_java_package
11+
*/
12+
@SuppressWarnings("UnusedDeclaration")
13+
public class Math {
14+
15+
public Math() {
16+
// some lambdas to cause Retrolambda try backporting this class
17+
Runnable r = () -> {
18+
};
19+
}
20+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,15 @@ public Runnable foo() {
5757
public void prefers_classes_in_explicit_classpath_over_classes_in_the_JRE() {
5858
assertNotNull(getClass().getResource("/com/sun/javafx/application/LauncherImpl$$Lambda$1.class"));
5959
}
60+
61+
/**
62+
* Classes in the {@code java.*} packages can be loaded only by the bootstrap
63+
* class loader, so we must not try to load them with our custom class loader.
64+
* This situation arises when backporting Android applications, because android.jar
65+
* contains {@code java.*} classes.
66+
*/
67+
@Test
68+
public void ignores_classes_in_explicit_classpath_that_are_under_the_java_package() {
69+
assertNotNull(getClass().getResource("/java/lang/Math.class"));
70+
}
6071
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ public class ClassHierarchyAnalyzer implements MethodRelocations {
2323

2424
public void analyze(byte[] bytecode) {
2525
ClassReader cr = new ClassReader(bytecode);
26-
Type clazz = classNameToType(cr.getClassName());
26+
String className = cr.getClassName();
27+
if (className.startsWith("java/")) {
28+
// the JVM disallows user classes in java.* packages, so don't even try backporting them
29+
return;
30+
}
31+
Type clazz = classNameToType(className);
2732

2833
if (Flags.hasFlag(cr.getAccess(), ACC_INTERFACE)) {
2934
interfaces.add(cr);

0 commit comments

Comments
 (0)