Skip to content

Commit

Permalink
8293003: Review running time of Warn5 regression test
Browse files Browse the repository at this point in the history
Reviewed-by: vromero
  • Loading branch information
jddarcy committed Sep 2, 2022
1 parent e0168a0 commit 3ac91b0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
12 changes: 7 additions & 5 deletions test/langtools/tools/javac/varargs/warning/Warn4.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,13 @@ boolean badTestFilter() {
return sigs[0].isApplicableTo(sigs[1]);
}

final String template = "import java.util.List;\n" +
"class Test {\n" +
" #{TRUSTME} #{SUPPRESS[0]} #{MOD} #{MTH[0].VARARG}\n" +
" #{SUPPRESS[1]} #{MTH[1].CLIENT}\n" +
"}";
final String template = """
import java.util.List;
class Test {
#{TRUSTME} #{SUPPRESS[0]} #{MOD} #{MTH[0].VARARG}
#{SUPPRESS[1]} #{MTH[1].CLIENT}
}
""";

@Override
public void doWork() throws IOException {
Expand Down
34 changes: 20 additions & 14 deletions test/langtools/tools/javac/varargs/warning/Warn5.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ public String expand(String optParameter) {
}
}

// Handling of varargs warnings changed in JDK 9 compared to JDK 8
// and then remained consistent; test 8 and then current release.
enum SourceLevel {
JDK_8("8"),
JDK_9("9"),
LATEST(Integer.toString(javax.lang.model.SourceVersion.latest().runtimeVersion().feature()));

String sourceKey;
Expand Down Expand Up @@ -159,12 +160,15 @@ public String expand(String optParameter) {
}
}

// javac does not currently perform analysis of the method body
// with respect to the validity of the @SafeVargs annotation. If
// that changes, the body tests should be expanded.
enum BodyKind implements ComboParameter {
ASSIGN("Object o = x;", true),
CAST("Object o = (Object)x;", true),
// ASSIGN("Object o = x;", true),
// CAST("Object o = (Object)x;", true),
METH("test(x);", true),
PRINT("System.out.println(x.toString());", false),
ARRAY_ASSIGN("Object[] o = x;", true),
// ARRAY_ASSIGN("Object[] o = x;", true),
ARRAY_CAST("Object[] o = (Object[])x;", true),
ARRAY_METH("testArr(x);", true);

Expand Down Expand Up @@ -222,13 +226,15 @@ boolean badTestFilter() {
return (methKind != MethodKind.CONSTRUCTOR || modKind == ModifierKind.NONE);
}

String template = "import com.sun.tools.javac.api.*;\n" +
"import java.util.List;\n" +
"class Test {\n" +
" static void test(Object o) {}\n" +
" static void testArr(Object[] o) {}\n" +
" #{TRUSTME} #{SUPPRESS} #{MOD} #{SIG} { #{BODY} }\n" +
"}\n";
String template = """
import com.sun.tols.javac.api.*;
import java.util.List;
class Test {
static void test(Object o) {}
static void testArr(Object[] o) {}
#{TRUSTME} #{SUPPRESS} #{MOD} #{SIG} { #{BODY} }
}
""";

@Override
public void doWork() throws IOException {
Expand Down Expand Up @@ -265,7 +271,7 @@ void check(Result<?> res) {
(methKind == MethodKind.CONSTRUCTOR ||
(methKind == MethodKind.METHOD &&
modKind == ModifierKind.FINAL || modKind == ModifierKind.STATIC ||
(modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) >= 0)))) {
(modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_8) > 0)))) {
expectedWarnings.add(WarningKind.UNSAFE_BODY);
}

Expand All @@ -279,7 +285,7 @@ void check(Result<?> res) {
if (trustMe == TrustMe.TRUST &&
(!sig.isVarargs ||
((modKind == ModifierKind.NONE ||
modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) < 0 ) &&
modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_8) <= 0 ) &&
methKind == MethodKind.METHOD))) {
expectedWarnings.add(WarningKind.MALFORMED_SAFEVARARGS);
}
Expand All @@ -288,7 +294,7 @@ void check(Result<?> res) {
xlint != XlintOption.NONE &&
suppressLevel != SuppressLevel.VARARGS &&
(modKind == ModifierKind.FINAL || modKind == ModifierKind.STATIC ||
(modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_9) >= 0) ||
(modKind == ModifierKind.PRIVATE && sourceLevel.compareTo(SourceLevel.JDK_8) > 0) ||
methKind == MethodKind.CONSTRUCTOR) &&
sig.isVarargs &&
sig.isReifiableArg) {
Expand Down

1 comment on commit 3ac91b0

@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.