Skip to content
This repository was archived by the owner on Aug 26, 2021. It is now read-only.

Commit 59c50c4

Browse files
committed
work-around bug in javac in Java 7
1 parent 8f4a753 commit 59c50c4

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

compiler/src/main/java/dagger/internal/codegen/GraphAnalysisLoader.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public GraphAnalysisLoader(ProcessingEnvironment processingEnv) {
6262
* in canonical class names).
6363
*/
6464
@VisibleForTesting static TypeElement resolveType(Elements elements, String className) {
65-
int index = nextDollar(className, className, 0);
65+
int index = next$(className, className, 0);
6666
if (index == -1) {
67-
return elements.getTypeElement(className);
67+
return getTypeElement(elements, className);
6868
}
6969
// have to test various possibilities of replacing '$' with '.' since '.' in a canonical name
7070
// of a nested type is replaced with '$' in the binary name.
@@ -85,27 +85,27 @@ private static TypeElement resolveType(Elements elements, String className, Stri
8585

8686
// We assume '$' should be converted to '.'. So we search for classes with dots first.
8787
sb.setCharAt(index, '.');
88-
int nextIndex = nextDollar(className, sb, index + 1);
88+
int nextIndex = next$(className, sb, index + 1);
8989
TypeElement type = nextIndex == -1
90-
? elements.getTypeElement(sb)
90+
? getTypeElement(elements, sb)
9191
: resolveType(elements, className, sb, nextIndex);
9292
if (type != null) {
9393
return type;
9494
}
9595

9696
// if not found, change back to dollar and search.
9797
sb.setCharAt(index, '$');
98-
nextIndex = nextDollar(className, sb, index + 1);
98+
nextIndex = next$(className, sb, index + 1);
9999
return nextIndex == -1
100-
? elements.getTypeElement(sb)
100+
? getTypeElement(elements, sb)
101101
: resolveType(elements, className, sb, nextIndex);
102102
}
103103

104104
/**
105105
* Finds the next {@code '$'} in a class name which can be changed to a {@code '.'} when computing
106106
* a canonical class name.
107107
*/
108-
private static int nextDollar(String className, CharSequence current, int searchStart) {
108+
private static int next$(String className, CharSequence current, int searchStart) {
109109
while (true) {
110110
int index = className.indexOf('$', searchStart);
111111
if (index == -1) {
@@ -122,6 +122,18 @@ private static int nextDollar(String className, CharSequence current, int search
122122
}
123123
}
124124

125+
private static TypeElement getTypeElement(Elements elements, CharSequence className) {
126+
try {
127+
return elements.getTypeElement(className);
128+
} catch (ClassCastException e) {
129+
// work-around issue in javac in Java 7 where querying for non-existent type can
130+
// throw a ClassCastException
131+
// TODO(jh): refer to Oracle Bug ID if/when one is assigned to bug report
132+
// (Review ID: JI-9027367)
133+
return null;
134+
}
135+
}
136+
125137
@Override public <T> ModuleAdapter<T> getModuleAdapter(Class<T> moduleClass) {
126138
throw new UnsupportedOperationException();
127139
}

0 commit comments

Comments
 (0)