test/tools/javac/varargs/warning/Warn5.java
Print this page
@@ -87,11 +87,12 @@
}
enum ModifierKind {
NONE(""),
FINAL("final"),
- STATIC("static");
+ STATIC("static"),
+ PRIVATE("private");
String mod;
ModifierKind(String mod) {
this.mod = mod;
@@ -109,11 +110,12 @@
}
}
enum SourceLevel {
JDK_6("6"),
- JDK_7("7");
+ JDK_7("7"),
+ JDK_9("9");
String sourceKey;
SourceLevel(String sourceKey) {
this.sourceKey = sourceKey;
@@ -236,44 +238,47 @@
void check() {
EnumSet<WarningKind> expectedWarnings =
EnumSet.noneOf(WarningKind.class);
- if (sourceLevel == SourceLevel.JDK_7 &&
+ if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
trustMe == TrustMe.TRUST &&
suppressLevel != SuppressLevel.VARARGS &&
xlint != XlintOption.NONE &&
sig.isVarargs &&
!sig.isReifiableArg &&
body.hasAliasing &&
(methKind == MethodKind.CONSTRUCTOR ||
(methKind == MethodKind.METHOD &&
- modKind != ModifierKind.NONE))) {
+ modKind == ModifierKind.FINAL || modKind == ModifierKind.STATIC ||
+ (modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) >= 0)))) {
expectedWarnings.add(WarningKind.UNSAFE_BODY);
}
- if (sourceLevel == SourceLevel.JDK_7 &&
+ if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
trustMe == TrustMe.DONT_TRUST &&
sig.isVarargs &&
!sig.isReifiableArg &&
xlint == XlintOption.ALL) {
expectedWarnings.add(WarningKind.UNSAFE_DECL);
}
- if (sourceLevel == SourceLevel.JDK_7 &&
+ if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
trustMe == TrustMe.TRUST &&
(!sig.isVarargs ||
- (modKind == ModifierKind.NONE &&
+ ((modKind == ModifierKind.NONE ||
+ modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) < 0 ) &&
methKind == MethodKind.METHOD))) {
expectedWarnings.add(WarningKind.MALFORMED_SAFEVARARGS);
}
- if (sourceLevel == SourceLevel.JDK_7 &&
+ if (sourceLevel.compareTo(SourceLevel.JDK_7) >= 0 &&
trustMe == TrustMe.TRUST &&
xlint != XlintOption.NONE &&
suppressLevel != SuppressLevel.VARARGS &&
- (modKind != ModifierKind.NONE ||
+ (modKind == ModifierKind.FINAL || modKind == ModifierKind.STATIC ||
+ (modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) >= 0) ||
methKind == MethodKind.CONSTRUCTOR) &&
sig.isVarargs &&
sig.isReifiableArg) {
expectedWarnings.add(WarningKind.REDUNDANT_SAFEVARARGS);
}
@@ -281,10 +286,11 @@
if (!expectedWarnings.containsAll(dc.warnings) ||
!dc.warnings.containsAll(expectedWarnings)) {
throw new Error("invalid diagnostics for source:\n" +
source.getCharContent(true) +
"\nOptions: " + xlint.getXlintOption() +
+ "\nSource Level: " + sourceLevel +
"\nExpected warnings: " + expectedWarnings +
"\nFound warnings: " + dc.warnings);
}
}