Skip to content

Commit 87804f2

Browse files
committed
8346294: Invalid lint category specified in compiler.properties
Reviewed-by: mcimadamore
1 parent 18d1d61 commit 87804f2

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

make/langtools/tools/propertiesparser/resources/templates.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -82,5 +82,5 @@ suppress.warnings=\
8282
@SuppressWarnings("rawtypes")\n
8383

8484
lint.category=\
85-
LintCategory.get({0})
85+
LintCategory.get({0}).get()
8686

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Arrays;
2929
import java.util.EnumSet;
3030
import java.util.Map;
31+
import java.util.Optional;
3132
import java.util.concurrent.ConcurrentHashMap;
3233

3334
import com.sun.tools.javac.code.Symbol.*;
@@ -362,8 +363,14 @@ public enum LintCategory {
362363
map.put(option, this);
363364
}
364365

365-
public static LintCategory get(String option) {
366-
return map.get(option);
366+
/**
367+
* Get the {@link LintCategory} having the given command line option.
368+
*
369+
* @param option lint category option string
370+
* @return corresponding {@link LintCategory}, or empty if none exists
371+
*/
372+
public static Optional<LintCategory> get(String option) {
373+
return Optional.ofNullable(map.get(option));
367374
}
368375

369376
public final String option;
@@ -441,9 +448,8 @@ private void suppress(LintCategory lc) {
441448

442449
public void visitConstant(Attribute.Constant value) {
443450
if (value.type.tsym == syms.stringType.tsym) {
444-
LintCategory lc = LintCategory.get((String) (value.value));
445-
if (lc != null)
446-
suppress(lc);
451+
LintCategory.get((String)value.value)
452+
.ifPresent(this::suppress);
447453
}
448454
}
449455

src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ compiler.warn.lintOption=\
18801880
compiler.warn.constant.SVUID=\
18811881
serialVersionUID must be constant in class {0}
18821882

1883-
# lint: dangling
1883+
# lint: dangling-doc-comments
18841884
compiler.warn.dangling.doc.comment=\
18851885
documentation comment is not attached to any declaration
18861886

0 commit comments

Comments
 (0)