Skip to content

Commit

Permalink
8303784: no-@target annotations should be applicable to type paramete…
Browse files Browse the repository at this point in the history
…r declarations

Reviewed-by: vromero
  • Loading branch information
cushon committed May 2, 2023
1 parent b76f320 commit 8c106b0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public enum Feature {
SWITCH_MULTIPLE_CASE_LABELS(JDK14, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
SWITCH_RULE(JDK14, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
SWITCH_EXPRESSION(JDK14, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
NO_TARGET_ANNOTATION_APPLICABILITY(JDK14),
TEXT_BLOCKS(JDK15, Fragments.FeatureTextBlocks, DiagKind.PLURAL),
PATTERN_MATCHING_IN_INSTANCEOF(JDK16, Fragments.FeaturePatternMatchingInstanceof, DiagKind.NORMAL),
REIFIABLE_TYPES_INSTANCEOF(JDK16, Fragments.FeatureReifiableTypesInstanceof, DiagKind.PLURAL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3513,7 +3513,7 @@ boolean isOverrider(Symbol s) {
protected boolean isTypeAnnotation(JCAnnotation a, boolean isTypeParameter) {
List<Attribute> targets = typeAnnotations.annotationTargets(a.annotationType.type.tsym);
return (targets == null) ?
false :
(Feature.NO_TARGET_ANNOTATION_APPLICABILITY.allowedInSource(source) && isTypeParameter) :
targets.stream()
.anyMatch(attr -> isTypeAnnotation(attr, isTypeParameter));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2023, Alphabet LLC. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test
* @bug 8303784
* @summary no-@Target annotations should be applicable to type parameter declarations
* @compile/fail/ref=NoTargetOnTypeParameterDeclaration.out --release 13 -XDrawDiagnostics NoTargetOnTypeParameterDeclaration.java
* @compile --release 14 NoTargetOnTypeParameterDeclaration.java
* @compile NoTargetOnTypeParameterDeclaration.java
*/

import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Retention;

class NoTargetOnTypeParameterDeclaration {

@Retention(RetentionPolicy.RUNTIME)
@interface A {}

class B<@A X> {
<@A Y> void f() {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NoTargetOnTypeParameterDeclaration.java:41:11: compiler.err.annotation.type.not.applicable.to.type: NoTargetOnTypeParameterDeclaration.A
NoTargetOnTypeParameterDeclaration.java:42:6: compiler.err.annotation.type.not.applicable.to.type: NoTargetOnTypeParameterDeclaration.A
2 errors

1 comment on commit 8c106b0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.