Skip to content

Commit

Permalink
Ensure AnnotationLiterals for java.lang annotations don't throw secur…
Browse files Browse the repository at this point in the history
…ity exceptions

Fixes: quarkusio#4659
  • Loading branch information
geoand authored and CSTDev committed Oct 22, 2019
1 parent 7cf7184 commit f31e8be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void testFoo() {
@Singleton
static class Configured {

@Deprecated
@Inject
@ConfigProperty(name = "foos")
String[] foos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,24 @@ static String componentType(MethodInfo method) {
}

static String generatedSharedName(DotName annotationName) {
// when the annotation is a java.lang annotation we need to use a different package in which to generate the literal
// otherwise a security exception will be thrown when the literal is loaded
String nameToUse = isJavaLang(annotationName.toString())
? AbstractGenerator.DEFAULT_PACKAGE + annotationName.withoutPackagePrefix()
: annotationName.toString();

// com.foo.MyQualifier -> com.foo.MyQualifier1_Shared_AnnotationLiteral
return annotationName + SHARED_SUFFIX + ANNOTATION_LITERAL_SUFFIX;
return nameToUse + SHARED_SUFFIX + ANNOTATION_LITERAL_SUFFIX;
}

private static boolean isJavaLang(String s) {
return s.startsWith("java.lang");
}

static String generatedLocalName(String targetPackage, String simpleName, String hash) {
// com.foo.MyQualifier -> com.bar.MyQualifier_somehashvalue_AnnotationLiteral
return targetPackage + "." + simpleName + hash + AnnotationLiteralGenerator.ANNOTATION_LITERAL_SUFFIX;
return (isJavaLang(targetPackage) ? AbstractGenerator.DEFAULT_PACKAGE : targetPackage) + "." + simpleName + hash
+ AnnotationLiteralGenerator.ANNOTATION_LITERAL_SUFFIX;
}

}

0 comments on commit f31e8be

Please sign in to comment.