Skip to content

Commit

Permalink
Update the behavior for JDK-7183985.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstancu committed Dec 21, 2018
1 parent 9d27d6f commit b06bfea
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
* https://bugs.openjdk.java.net/browse/JDK-7183985: when an annotation declares a Class<?> array
* parameter and one of the referenced classes is not present on the classpath parsing the
* annotations will result in an ArrayStoreException instead of caching of a
* TypeNotPresentExceptionProxy. This is problem in JDK8 but was fixed in JDK11+ and it should be
* soon back-ported to JDK8 too.
* TypeNotPresentExceptionProxy. This is a problem in JDK8 but was fixed in JDK11+.
*/
public final class AnnotationAccess {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public final class AnnotationsEncoding {
public static Annotation[] getAnnotations(Object annotationsEncoding) {
if (annotationsEncoding == null) {
return EMPTY_ANNOTATION_ARRAY;
} else if (annotationsEncoding instanceof ArrayStoreException) {
/* JDK-7183985 was hit at image build time when the annotations were encoded. */
throw (ArrayStoreException) annotationsEncoding;
} else if (annotationsEncoding instanceof Annotation[]) {
return ((Annotation[]) annotationsEncoding).clone();
} else {
Expand All @@ -45,7 +48,9 @@ public static Annotation[] getAnnotations(Object annotationsEncoding) {
public static <T extends Annotation> T getAnnotation(Object annotationsEncoding, Class<T> annotationClass) {
Objects.requireNonNull(annotationClass);

if (annotationsEncoding instanceof Annotation[]) {
if (annotationsEncoding instanceof ArrayStoreException) {
throw (ArrayStoreException) annotationsEncoding;
} else if (annotationsEncoding instanceof Annotation[]) {
for (Annotation annotation : (Annotation[]) annotationsEncoding) {
if (annotationClass.isInstance(annotation)) {
return (T) annotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,17 @@ private void checkType(AnalysisType type) {
/*
* Support for Java annotations.
*/
hub.setAnnotationsEncoding(encodeAnnotations(metaAccess, type.getAnnotations(), hub.getAnnotationsEncoding()));
try {
/*
* Get the annotations from the wrapped type since AnalysisType.getAnnotations()
* defends against JDK-7183985 and we want to get the original behavior.
*/
Annotation[] annotations = type.getWrapped().getAnnotations();
hub.setAnnotationsEncoding(encodeAnnotations(metaAccess, annotations, hub.getAnnotationsEncoding()));
} catch (ArrayStoreException e) {
/* If we hit JDK-7183985 just encode the exception. */
hub.setAnnotationsEncoding(e);
}

/*
* Support for Java enumerations.
Expand Down

0 comments on commit b06bfea

Please sign in to comment.