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

Commit

Permalink
work-around bug in javac in Java 7
Browse files Browse the repository at this point in the history
  • Loading branch information
jhump committed Dec 10, 2015
1 parent 8f4a753 commit 3f0db82
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public GraphAnalysisLoader(ProcessingEnvironment processingEnv) {
@VisibleForTesting static TypeElement resolveType(Elements elements, String className) {
int index = nextDollar(className, className, 0);
if (index == -1) {
return elements.getTypeElement(className);
return getTypeElement(elements, className);
}
// have to test various possibilities of replacing '$' with '.' since '.' in a canonical name
// of a nested type is replaced with '$' in the binary name.
Expand All @@ -87,7 +87,7 @@ private static TypeElement resolveType(Elements elements, String className, Stri
sb.setCharAt(index, '.');
int nextIndex = nextDollar(className, sb, index + 1);
TypeElement type = nextIndex == -1
? elements.getTypeElement(sb)
? getTypeElement(elements, sb)
: resolveType(elements, className, sb, nextIndex);
if (type != null) {
return type;
Expand All @@ -97,7 +97,7 @@ private static TypeElement resolveType(Elements elements, String className, Stri
sb.setCharAt(index, '$');
nextIndex = nextDollar(className, sb, index + 1);
return nextIndex == -1
? elements.getTypeElement(sb)
? getTypeElement(elements, sb)
: resolveType(elements, className, sb, nextIndex);
}

Expand All @@ -122,6 +122,18 @@ private static int nextDollar(String className, CharSequence current, int search
}
}

private static TypeElement getTypeElement(Elements elements, CharSequence className) {
try {
return elements.getTypeElement(className);
} catch (ClassCastException e) {
// work-around issue in javac in Java 7 where querying for non-existent type can
// throw a ClassCastException
// TODO(jh): refer to Oracle Bug ID if/when one is assigned to bug report
// (Review ID: JI-9027367)
return null;
}
}

@Override public <T> ModuleAdapter<T> getModuleAdapter(Class<T> moduleClass) {
throw new UnsupportedOperationException();
}
Expand Down

0 comments on commit 3f0db82

Please sign in to comment.