From 87804f24b2afaf7de4a21c81ef01548b09ba81b0 Mon Sep 17 00:00:00 2001 From: Archie Cobbs Date: Tue, 17 Dec 2024 03:18:25 +0000 Subject: [PATCH] 8346294: Invalid lint category specified in compiler.properties Reviewed-by: mcimadamore --- .../resources/templates.properties | 4 ++-- .../classes/com/sun/tools/javac/code/Lint.java | 16 +++++++++++----- .../tools/javac/resources/compiler.properties | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/make/langtools/tools/propertiesparser/resources/templates.properties b/make/langtools/tools/propertiesparser/resources/templates.properties index bb403238f80..991739aa403 100644 --- a/make/langtools/tools/propertiesparser/resources/templates.properties +++ b/make/langtools/tools/propertiesparser/resources/templates.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2015, 2024, Oracle and/or its affiliates. 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 @@ -82,5 +82,5 @@ suppress.warnings=\ @SuppressWarnings("rawtypes")\n lint.category=\ - LintCategory.get({0}) + LintCategory.get({0}).get() diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java index c55830849c8..e28c0fe60f8 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java @@ -28,6 +28,7 @@ package com.sun.tools.javac.code; import java.util.Arrays; import java.util.EnumSet; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import com.sun.tools.javac.code.Symbol.*; @@ -362,8 +363,14 @@ public class Lint map.put(option, this); } - public static LintCategory get(String option) { - return map.get(option); + /** + * Get the {@link LintCategory} having the given command line option. + * + * @param option lint category option string + * @return corresponding {@link LintCategory}, or empty if none exists + */ + public static Optional get(String option) { + return Optional.ofNullable(map.get(option)); } public final String option; @@ -441,9 +448,8 @@ public class Lint public void visitConstant(Attribute.Constant value) { if (value.type.tsym == syms.stringType.tsym) { - LintCategory lc = LintCategory.get((String) (value.value)); - if (lc != null) - suppress(lc); + LintCategory.get((String)value.value) + .ifPresent(this::suppress); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties index 99baf519958..2e7183dfbed 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -1880,7 +1880,7 @@ compiler.warn.lintOption=\ compiler.warn.constant.SVUID=\ serialVersionUID must be constant in class {0} -# lint: dangling +# lint: dangling-doc-comments compiler.warn.dangling.doc.comment=\ documentation comment is not attached to any declaration