From 72b2d5ac9981ae8c9d85daef43d01d0a4c3789d7 Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Fri, 29 Nov 2024 19:13:34 +0000 Subject: [PATCH 01/10] Tweak warning keys in compiler.properties Initial stab at adding a new LintWarning info --- .../com/sun/tools/javac/code/Lint.java | 2 +- .../tools/javac/resources/compiler.properties | 198 +++++++++--------- .../javac/resources/compiler_de.properties | 18 +- .../javac/resources/compiler_ja.properties | 18 +- .../javac/resources/compiler_zh_CN.properties | 18 +- .../com/sun/tools/javac/util/AbstractLog.java | 37 +--- .../sun/tools/javac/util/JCDiagnostic.java | 84 ++++---- .../examples/SerialMissingNoArgCtor.java | 2 +- .../examples/SerialNonPrivateMethod.java | 16 +- .../javac/warnings/Serial/CtorAccess.out | 4 +- .../warnings/Serial/ImproperReturnTypes.out | 10 +- .../warnings/Serial/SerialMethodArity.out | 10 +- .../warnings/Serial/SerialMethodMods.out | 10 +- .../warnings/Serial/SerialMethodThrows.out | 10 +- 14 files changed, 210 insertions(+), 227 deletions(-) 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 622c13d8b4797..af2d98d6c11ae 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 @@ -359,7 +359,7 @@ public enum LintCategory { map.put(option, this); } - static LintCategory get(String option) { + public static LintCategory get(String option) { return map.get(option); } 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 bd666f3427dd7..c26a1b7f19955 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 @@ -708,10 +708,10 @@ compiler.err.not.in.profile=\ compiler.warn.forward.ref=\ reference to variable ''{0}'' before it has been initialized -compiler.warn.possible.this.escape=\ +compiler.warn.lint.this-escape.possible.this.escape=\ possible ''this'' escape before subclass is fully initialized -compiler.warn.possible.this.escape.location=\ +compiler.warn.lint.this-escape.possible.this.escape.location=\ previous possible ''this'' escape happens here via invocation compiler.err.illegal.self.ref=\ @@ -731,10 +731,10 @@ compiler.err.illegal.line.end.in.char.lit=\ compiler.err.illegal.text.block.open=\ illegal text block open delimiter sequence, missing line terminator -compiler.warn.inconsistent.white.space.indentation=\ +compiler.warn.lint.text-blocks.inconsistent.white.space.indentation=\ inconsistent white space indentation -compiler.warn.trailing.white.space.will.be.removed=\ +compiler.warn.lint.text-blocks.trailing.white.space.will.be.removed=\ trailing white space will be removed compiler.err.illegal.nonascii.digit=\ @@ -1594,7 +1594,7 @@ compiler.err.multi-module.outdir.cannot.be.exploded.module=\ in multi-module mode, the output directory cannot be an exploded module: {0} # 0: path -compiler.warn.outdir.is.in.exploded.module=\ +compiler.warn.lint.path.outdir.is.in.exploded.module=\ the output directory is within an exploded module: {0} # 0: file object @@ -1661,7 +1661,7 @@ compiler.warn.file.from.future=\ Modification date is in the future for file {0} # 0: path -compiler.warn.output.file.clash=\ +compiler.warn.lint.output-file-clash.output.file.clash=\ output file written more than once: {0} ##### @@ -1876,41 +1876,41 @@ compiler.warn.lintOption=\ compiler.warn.constant.SVUID=\ serialVersionUID must be constant in class {0} -compiler.warn.dangling.doc.comment=\ +compiler.warn.lint.dangling.dangling.doc.comments=\ documentation comment is not attached to any declaration # 0: path -compiler.warn.dir.path.element.not.found=\ +compiler.warn.lint.path.dir.path.element.not.found=\ bad path element "{0}": no such directory # 0: file name -compiler.warn.dir.path.element.not.directory=\ +compiler.warn.lint.path.dir.path.element.not.directory=\ bad path element "{0}": not a directory # 0: symbol, 1: symbol, 2: symbol -compiler.warn.missing-explicit-ctor=\ +compiler.warn.lint.missing-explicit-ctor.missing.explicit.ctor=\ class {0} in exported package {1} declares no explicit constructors, thereby exposing a default constructor to clients of module {2} -compiler.warn.strictfp=\ +compiler.warn.lint.strictfp.strictfp=\ as of release 17, all floating-point expressions are evaluated strictly and ''strictfp'' is not required -compiler.warn.finally.cannot.complete=\ +compiler.warn.lint.finally.finally.cannot.complete=\ finally clause cannot complete normally # 0: name -compiler.warn.poor.choice.for.module.name=\ +compiler.warn.lint.module.poor.choice.for.module.name=\ module name component {0} should avoid terminal digits # 0: string -compiler.warn.incubating.modules=\ +compiler.warn.lint.incubating.incubating.modules=\ using incubating module(s): {0} # 0: symbol, 1: symbol -compiler.warn.has.been.deprecated=\ +compiler.warn.lint.deprecation.has.been.deprecated=\ {0} in {1} has been deprecated # 0: symbol, 1: symbol -compiler.warn.has.been.deprecated.for.removal=\ +compiler.warn.lint.removal.has.been.deprecated.for.removal=\ {0} in {1} has been deprecated and marked for removal # 0: symbol @@ -1927,16 +1927,16 @@ compiler.warn.is.preview.reflective=\ {0} is a reflective preview API and may be removed in a future release. # 0: symbol, 1: symbol -compiler.warn.restricted.method=\ +compiler.warn.restricted.restricted.method=\ {0}.{1} is a restricted method.\n\ (Restricted methods are unsafe and, if used incorrectly, might crash the Java runtime or corrupt memory) # 0: symbol -compiler.warn.has.been.deprecated.module=\ +compiler.warn.lint.deprecation.has.been.deprecated.module=\ module {0} has been deprecated # 0: symbol -compiler.warn.has.been.deprecated.for.removal.module=\ +compiler.warn.lint.removal.has.been.deprecated.for.removal.module=\ module {0} has been deprecated and marked for removal # 0: symbol @@ -1990,36 +1990,36 @@ compiler.warn.serializable.missing.access.no.arg.ctor=\ cannot access a no-arg constructor in first non-serializable superclass {0} # 0: name -compiler.warn.serial.method.not.private=\ +compiler.warn.lint.serial.serial.method.not.private=\ serialization-related method {0} not declared private # 0: name -compiler.warn.serial.concrete.instance.method=\ +compiler.warn.lint.serial.serial.concrete.instance.method=\ serialization-related method {0} must be a concrete instance method to be effective, neither abstract nor static # 0: name -compiler.warn.serial.method.static=\ +compiler.warn.lint.serial.serial.method.static=\ serialization-related method {0} declared static; must instead be an instance method to be effective # 0: name -compiler.warn.serial.method.no.args=\ +compiler.warn.lint.serial.serial.method.no.args=\ to be effective serialization-related method {0} must have no parameters # 0: name, 1: number -compiler.warn.serial.method.one.arg=\ +compiler.warn.lint.serial.serial.method.one.arg=\ to be effective serialization-related method {0} must have exactly one parameter rather than {1} parameters # 0: name, 1: type, 2: type -compiler.warn.serial.method.parameter.type=\ +compiler.warn.lint.serial.serial.method.parameter.type=\ sole parameter of serialization-related method {0} must have type {1} to be effective rather than type {2} # 0: name, 1: type, 2: type -compiler.warn.serial.method.unexpected.return.type=\ +compiler.warn.lint.serial.serial.method.unexpected.return.type=\ serialization-related method {0} declared with a return type of {1} rather than expected type {2}.\n\ As declared, the method will be ineffective for serialization # 0: name, 1: type -compiler.warn.serial.method.unexpected.exception=\ +compiler.warn.lint.serial.serial.method.unexpected.exception=\ serialization-related method {0} declared to throw an unexpected type {1} compiler.warn.ineffectual.serial.field.interface=\ @@ -2073,15 +2073,15 @@ compiler.warn.default.ineffective=\ serialization-related default method from an interface will not be run by serialization for an implementing class # 0: symbol, 1: symbol, 2: symbol, 3: symbol -compiler.warn.potentially.ambiguous.overload=\ +compiler.warn.lint.overloads.potentially.ambiguous.overload=\ {0} in {1} is potentially ambiguous with {2} in {3} # 0: message segment -compiler.warn.override.varargs.missing=\ +compiler.warn.lint.overrides.override.varargs.missing=\ {0}; overridden method has no ''...'' # 0: message segment -compiler.warn.override.varargs.extra=\ +compiler.warn.lint.overrides.override.varargs.extra=\ {0}; overriding method is missing ''...'' # 0: message segment @@ -2093,14 +2093,14 @@ compiler.warn.pkg-info.already.seen=\ a package-info.java file has already been seen for package {0} # 0: path -compiler.warn.path.element.not.found=\ +compiler.warn.lint.path.path.element.not.found=\ bad path element "{0}": no such file or directory -compiler.warn.possible.fall-through.into.case=\ +compiler.warn.fallthrough.possible.fall-through.into.case=\ possible fall-through into case # 0: type -compiler.warn.redundant.cast=\ +compiler.warn.lint.cast.redundant.cast=\ redundant cast to {0} # 0: number @@ -2117,19 +2117,19 @@ compiler.warn.invalid.utf8.in.classfile=\ {0}: classfile contains invalid UTF-8: {1} # 0: kind name, 1: symbol -compiler.warn.static.not.qualified.by.type=\ +compiler.warn.lint.static.static.not.qualified.by.type=\ static {0} should be qualified by type name, {1}, instead of by an expression # 0: kind name -compiler.warn.static.not.qualified.by.type2=\ +compiler.warn..lint.static.static.not.qualified.by.type2=\ static {0} should not be used as a member of an anonymous class # 0: string, 1: fragment -compiler.warn.source.no.bootclasspath=\ +compiler.warn.lint.options.source.no.bootclasspath=\ bootstrap class path is not set in conjunction with -source {0}\n{1} # 0: string, 1: fragment -compiler.warn.source.no.system.modules.path=\ +compiler.warn.lint.options.source.no.system.modules.path=\ location of system modules is not set in conjunction with -source {0}\n{1} # 0: string @@ -2153,11 +2153,11 @@ compiler.misc.source.no.system.modules.path.with.target=\ --release {0} is recommended instead of -source {0} -target {1} because it sets the location of system modules automatically # 0: string -compiler.warn.option.obsolete.source=\ +compiler.warn.lint.options.option.obsolete.source=\ source value {0} is obsolete and will be removed in a future release # 0: target -compiler.warn.option.obsolete.target=\ +compiler.warn.lint.options.option.obsolete.target=\ target value {0} is obsolete and will be removed in a future release # 0: string, 1: string @@ -2168,149 +2168,149 @@ compiler.err.option.removed.source=\ compiler.err.option.removed.target=\ Target option {0} is no longer supported. Use {1} or later. -compiler.warn.option.obsolete.suppression=\ +compiler.warn.lint.options.option.obsolete.suppression=\ To suppress warnings about obsolete options, use -Xlint:-options. # 0: name, 1: number, 2: number, 3: number, 4: number -compiler.warn.future.attr=\ +compiler.warn.lint.classfile.future.attr=\ {0} attribute introduced in version {1}.{2} class files is ignored in version {3}.{4} class files -compiler.warn.requires.automatic=\ +compiler.warn.lint.requires-automatic.requires.automatic=\ requires directive for an automatic module -compiler.warn.requires.transitive.automatic=\ +compiler.warn.lint.requires-transitive-automatic.requires.transitive.automatic=\ requires transitive directive for an automatic module # Warnings related to annotation processing # 0: string -compiler.warn.proc.package.does.not.exist=\ +compiler.warn.lint.processing.proc.package.does.not.exist=\ package {0} does not exist # 0: string -compiler.warn.proc.file.reopening=\ +compiler.warn.lint.processing.proc.file.reopening=\ Attempt to create a file for ''{0}'' multiple times # 0: string -compiler.warn.proc.type.already.exists=\ +compiler.warn.lint.processing.proc.type.already.exists=\ A file for type ''{0}'' already exists on the sourcepath or classpath # 0: string -compiler.warn.proc.type.recreate=\ +compiler.warn.lint.processing.proc.type.recreate=\ Attempt to create a file for type ''{0}'' multiple times # 0: string -compiler.warn.proc.illegal.file.name=\ +compiler.warn.lint.processing.proc.illegal.file.name=\ Cannot create file for illegal name ''{0}''. # 0: string, 1: string -compiler.warn.proc.suspicious.class.name=\ +compiler.warn.lint.processing.proc.suspicious.class.name=\ Creating file for a type whose name ends in {1}: ''{0}'' # 0: string -compiler.warn.proc.file.create.last.round=\ +compiler.warn.lint.processing.proc.file.create.last.round=\ File for type ''{0}'' created in the last round will not be subject to annotation processing. # 0: string, 1: string -compiler.warn.proc.malformed.supported.string=\ +compiler.warn.lint.processing.proc.malformed.supported.string=\ Malformed string ''{0}'' for a supported annotation interface returned by processor ''{1}'' # 0: set of string -compiler.warn.proc.annotations.without.processors=\ +compiler.warn.lint.processing.proc.annotations.without.processors=\ No processor claimed any of these annotations: {0} # 0: source version, 1: string, 2: string -compiler.warn.proc.processor.incompatible.source.version=\ +compiler.warn.lint.processing.proc.processor.incompatible.source.version=\ Supported source version ''{0}'' from annotation processor ''{1}'' less than -source ''{2}'' # 0: string, 1: string -compiler.warn.proc.duplicate.option.name=\ +compiler.warn.lint.processing.proc.duplicate.option.name=\ Duplicate supported option ''{0}'' returned by annotation processor ''{1}'' # 0: string, 1: string -compiler.warn.proc.duplicate.supported.annotation=\ +compiler.warn.lint.processing.proc.duplicate.supported.annotation=\ Duplicate supported annotation interface ''{0}'' returned by annotation processor ''{1}'' # 0: string -compiler.warn.proc.redundant.types.with.wildcard=\ +compiler.warn.lint.processing.proc.redundant.types.with.wildcard=\ Annotation processor ''{0}'' redundantly supports both ''*'' and other annotation interfaces -compiler.warn.proc.proc-only.requested.no.procs=\ +compiler.warn.lint.processing.proc.proc-only.requested.no.procs=\ Annotation processing without compilation requested but no processors were found. -compiler.warn.proc.use.implicit=\ +compiler.warn.lint.processing.proc.use.implicit=\ Implicitly compiled files were not subject to annotation processing.\n\ Use -implicit to specify a policy for implicit compilation. -compiler.warn.proc.use.proc.or.implicit=\ +compiler.warn.lint.processing.proc.use.proc.or.implicit=\ Implicitly compiled files were not subject to annotation processing.\n\ Use -proc:none to disable annotation processing or -implicit to specify a policy for implicit compilation. # Print a client-generated warning; assumed to be localized, no translation required # 0: string -compiler.warn.proc.messager=\ +compiler.warn.lint.processing.proc.messager=\ {0} # 0: set of string -compiler.warn.proc.unclosed.type.files=\ +compiler.warn.lint.processing.proc.unclosed.type.files=\ Unclosed files for the types ''{0}''; these types will not undergo annotation processing # 0: string -compiler.warn.proc.unmatched.processor.options=\ +compiler.warn.lint.processing.proc.unmatched.processor.options=\ The following options were not recognized by any processor: ''{0}'' -compiler.warn.try.explicit.close.call=\ +compiler.warn.lint.try.try.explicit.close.call=\ explicit call to close() on an auto-closeable resource # 0: symbol -compiler.warn.try.resource.not.referenced=\ +compiler.warn.lint.try.try.resource.not.referenced=\ auto-closeable resource {0} is never referenced in body of corresponding try statement # 0: type -compiler.warn.try.resource.throws.interrupted.exc=\ +compiler.warn.lint.try.try.resource.throws.interrupted.exc=\ auto-closeable resource {0} has a member method close() that could throw InterruptedException -compiler.warn.unchecked.assign=\ +compiler.warn.lint.unchecked.unchecked.assign=\ unchecked assignment: {0} to {1} # 0: symbol, 1: type -compiler.warn.unchecked.assign.to.var=\ +compiler.warn.lint.unchecked.unchecked.assign.to.var=\ unchecked assignment to variable {0} as member of raw type {1} # 0: symbol, 1: type -compiler.warn.unchecked.call.mbr.of.raw.type=\ +compiler.warn.lint.unchecked.unchecked.call.mbr.of.raw.type=\ unchecked call to {0} as a member of the raw type {1} -compiler.warn.unchecked.cast.to.type=\ +compiler.warn.lint.unchecked.unchecked.cast.to.type=\ unchecked cast to type {0} # 0: kind name, 1: name, 2: object, 3: object, 4: kind name, 5: symbol -compiler.warn.unchecked.meth.invocation.applied=\ +compiler.warn.lint.unchecked.unchecked.meth.invocation.applied=\ unchecked method invocation: {0} {1} in {4} {5} is applied to given types\n\ required: {2}\n\ found: {3} # 0: type -compiler.warn.unchecked.generic.array.creation=\ +compiler.warn.lint.unchecked.unchecked.generic.array.creation=\ unchecked generic array creation for varargs parameter of type {0} # 0: type -compiler.warn.unchecked.varargs.non.reifiable.type=\ +compiler.warn.lint.unchecked.unchecked.varargs.non.reifiable.type=\ Possible heap pollution from parameterized vararg type {0} # 0: symbol -compiler.warn.varargs.unsafe.use.varargs.param=\ +compiler.warn.lint.varargs.varargs.unsafe.use.varargs.param=\ Varargs method could cause heap pollution from non-reifiable varargs parameter {0} -compiler.warn.missing.deprecated.annotation=\ +compiler.warn.lint.dep-ann.missing.deprecated.annotation=\ deprecated item is not annotated with @Deprecated # 0: kind name -compiler.warn.deprecated.annotation.has.no.effect=\ +compiler.warn.lint.deprecation.deprecated.annotation.has.no.effect=\ @Deprecated annotation has no effect on this {0} declaration # 0: string -compiler.warn.invalid.path=\ +compiler.warn.lint.path.invalid.path=\ Invalid filename: {0} compiler.warn.doclint.not.available=\ @@ -2322,21 +2322,21 @@ compiler.err.invalid.path=\ # 0: path -compiler.warn.invalid.archive.file=\ +compiler.warn.lint.path.invalid.archive.file=\ Unexpected file on path: {0} # 0: path -compiler.warn.unexpected.archive.file=\ +compiler.warn.lint.path.unexpected.archive.file=\ Unexpected extension for archive file: {0} # 0: path compiler.err.no.zipfs.for.archive=\ No file system provider is available to handle this file: {0} -compiler.warn.div.zero=\ +compiler.warn.lint.divzero.div.zero=\ division by zero -compiler.warn.empty.if=\ +compiler.warn.lint.empty.empty.if=\ empty statement after if # 0: type, 1: name @@ -2362,7 +2362,7 @@ compiler.warn.unknown.enum.constant.reason=\ reason: {3} # 0: type, 1: type -compiler.warn.raw.class.use=\ +compiler.warn.lint.rawtypes.raw.class.use=\ found raw type: {0}\n\ missing type arguments for generic class {1} @@ -2379,7 +2379,7 @@ compiler.warn.method.redundant.typeargs=\ Redundant type arguments in method call. # 0: symbol, 1: message segment -compiler.warn.varargs.redundant.trustme.anno=\ +compiler.warn.lint.varargs.varargs.redundant.trustme.anno=\ Redundant {0} annotation. {1} # 0: symbol @@ -2544,13 +2544,13 @@ compiler.misc.bad.enclosing.method=\ bad enclosing method attribute for class {0} # 0: file name -compiler.warn.runtime.visible.invisible.param.annotations.mismatch=\ +compiler.warn.lint.classfile.runtime.visible.invisible.param.annotations.mismatch=\ the length of parameters in RuntimeVisibleParameterAnnotations attribute and \ RuntimeInvisibleParameterAnnotations attribute in: {0} \ do not match, ignoring both attributes # 0: file name -compiler.warn.runtime.invisible.parameter.annotations=\ +compiler.warn.lint.classfile.runtime.invisible.parameter.annotations=\ the RuntimeVisibleParameterAnnotations and RuntimeInvisibleParameterAnnotations attributes \ in: {0} \ cannot be mapped to the method''s parameters @@ -2690,7 +2690,7 @@ compiler.misc.possible.loss.of.precision=\ possible lossy conversion from {0} to {1} # 0: type, 1: type -compiler.warn.possible.loss.of.precision=\ +compiler.warn.lint.lossy-conversions.possible.loss.of.precision=\ implicit cast from {0} to {1} in compound assignment is possibly lossy compiler.misc.unchecked.assign=\ @@ -2865,7 +2865,7 @@ compiler.misc.varargs.argument.mismatch=\ ##### # 0: symbol or type, 1: file name -compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file=\ +compiler.warn.lint.auxiliaryclass.auxiliary.class.accessed.from.outside.of.its.source.file=\ auxiliary class {0} in {1} should not be accessed from outside its own source file ## The first argument ({0}) is a "kindname". @@ -3079,7 +3079,7 @@ compiler.warn.override.unchecked.thrown=\ overridden method does not throw {1} # 0: symbol -compiler.warn.override.equals.but.not.hashcode=\ +compiler.warn.lint.overrides.override.equals.but.not.hashcode=\ Class {0} overrides equals, but neither it nor any superclass overrides hashCode method ## The following are all possible strings for the first argument ({0}) of the @@ -3171,15 +3171,15 @@ compiler.err.preview.feature.disabled.classfile=\ (use --enable-preview to allow loading of class files which contain preview features) # 0: message segment (feature) -compiler.warn.preview.feature.use=\ +compiler.warn.preview.preview.feature.use=\ {0} is a preview feature and may be removed in a future release. # 0: message segment (feature) -compiler.warn.preview.feature.use.plural=\ +compiler.warn.preview.preview.feature.use.plural=\ {0} are a preview feature and may be removed in a future release. # 0: file object (classfile), 1: string (expected version) -compiler.warn.preview.feature.use.classfile=\ +compiler.warn.preview.preview.feature.use.classfile=\ class file for {0} uses preview features of Java SE {1}. compiler.misc.feature.modules=\ @@ -3561,7 +3561,7 @@ compiler.err.module.not.found=\ module not found: {0} # 0: symbol -compiler.warn.module.not.found=\ +compiler.warn.lint.module.module.not.found=\ module not found: {0} # 0: name @@ -3656,7 +3656,7 @@ compiler.err.package.empty.or.not.found=\ package is empty or does not exist: {0} # 0: symbol -compiler.warn.package.empty.or.not.found=\ +compiler.warn.lint.opens.package.empty.or.not.found=\ package is empty or does not exist: {0} compiler.err.no.output.dir=\ @@ -3739,7 +3739,7 @@ compiler.err.bad.name.for.option=\ bad name in value for {0} option: ''{1}'' # 0: option name, 1: symbol -compiler.warn.module.for.option.not.found=\ +compiler.warn.lint.options.module.for.option.not.found=\ module name in {0} option not found: {1} compiler.err.addmods.all.module.path.invalid=\ @@ -3754,7 +3754,7 @@ compiler.err.add.exports.with.release=\ compiler.err.add.reads.with.release=\ adding read edges for system module {0} is not allowed with --release -compiler.warn.addopens.ignored=\ +compiler.warn.lint.options.addopens.ignored=\ --add-opens has no effect at compile time compiler.misc.locn.module_source_path=\ @@ -3784,16 +3784,16 @@ compiler.warn.service.provided.but.not.exported.or.used=\ service interface provided but not exported or used # 0: kind name, 1: symbol, 2: symbol -compiler.warn.leaks.not.accessible=\ +compiler.warn.lint.exports.leaks.not.accessible=\ {0} {1} in module {2} is not accessible to clients that require this module # 0: kind name, 1: symbol, 2: symbol -compiler.warn.leaks.not.accessible.unexported=\ +compiler.warn.lint.exports.leaks.not.accessible.unexported=\ {0} {1} in module {2} is not exported # 0: kind name, 1: symbol, 2: symbol -compiler.warn.leaks.not.accessible.not.required.transitive=\ +compiler.warn.lint.exports.leaks.not.accessible.not.required.transitive=\ {0} {1} in module {2} is not indirectly exported using ''requires transitive'' # 0: kind name, 1: symbol, 2: symbol -compiler.warn.leaks.not.accessible.unexported.qualified=\ +compiler.warn.lint.exports.leaks.not.accessible.unexported.qualified=\ {0} {1} in module {2} may not be visible to all clients that require this module ### @@ -4125,7 +4125,7 @@ compiler.err.incorrect.number.of.nested.patterns=\ compiler.warn.declared.using.preview=\ {0} {1} is declared using a preview feature, which may be removed in a future release. -compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class=\ +compiler.warn.lint.synchronization.attempt.to.synchronize.on.instance.of.value.based.class=\ attempt to synchronize on an instance of a value-based class # 0: type diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_de.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_de.properties index 33063b6558d3a..0192693dc1910 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_de.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_de.properties @@ -1414,31 +1414,31 @@ compiler.warn.OSF.array.SPF=serialPersistentFields muss den Typ "java.io.ObjectS compiler.warn.missing.SVUID=Serialisierbare Klasse {0} enthält keine Definition von serialVersionUID # 0: name -compiler.warn.serializable.missing.access.no.arg.ctor=Zugriff auf einen no-arg-Konstruktor in der ersten nicht serialisierbaren Superklasse {0} nicht möglich +compiler.warn.lint.serializable.missing.access.no.arg.ctor=Zugriff auf einen no-arg-Konstruktor in der ersten nicht serialisierbaren Superklasse {0} nicht möglich # 0: name -compiler.warn.serial.method.not.private=Serialisierungsbezogene Methode {0} nicht als privat deklariert +compiler.warn.lint.serial.method.not.private=Serialisierungsbezogene Methode {0} nicht als privat deklariert # 0: name -compiler.warn.serial.concrete.instance.method=Serialisierungsbezogene Methode {0} muss eine konkrete Instanzmethode sein, um in Kraft zu treten. Sie darf nicht abstrakt oder statisch sein +compiler.warn.lint.serial.concrete.instance.method=Serialisierungsbezogene Methode {0} muss eine konkrete Instanzmethode sein, um in Kraft zu treten. Sie darf nicht abstrakt oder statisch sein # 0: name -compiler.warn.serial.method.static=Serialisierungsbezogene Methode {0} ist als statisch deklariert. Sie muss stattdessen eine Instanzmethode sein, um in Kraft zu treten. +compiler.warn.lint.serial.method.static=Serialisierungsbezogene Methode {0} ist als statisch deklariert. Sie muss stattdessen eine Instanzmethode sein, um in Kraft zu treten. # 0: name -compiler.warn.serial.method.no.args=Serialisierungsbezogene Methode {0} darf keine Parameter aufweisen, um in Kraft zu treten +compiler.warn.lint.serial.method.no.args=Serialisierungsbezogene Methode {0} darf keine Parameter aufweisen, um in Kraft zu treten # 0: name, 1: number -compiler.warn.serial.method.one.arg=Serialisierungsbezogene Methode {0} muss genau einen Parameter aufweisen, um in Kraft zu treten. Sie darf nicht {1} Parameter enthalten +compiler.warn.lint.serial.method.one.arg=Serialisierungsbezogene Methode {0} muss genau einen Parameter aufweisen, um in Kraft zu treten. Sie darf nicht {1} Parameter enthalten # 0: name, 1: type, 2: type -compiler.warn.serial.method.parameter.type=Der einzige Parameter der serialisierungsbezogenen Methode {0} muss den Typ {1} haben, um in Kraft zu treten. Er darf nicht den Typ {2} aufweisen +compiler.warn.lint.serial.method.parameter.type=Der einzige Parameter der serialisierungsbezogenen Methode {0} muss den Typ {1} haben, um in Kraft zu treten. Er darf nicht den Typ {2} aufweisen # 0: name, 1: type, 2: type -compiler.warn.serial.method.unexpected.return.type=Serialisierungsbezogene Methode {0} wurde mit dem Rückgabetyp {1} und nicht dem erwarteten Typ {2} deklariert.\nMit dieser Deklaration ist die Methode ungültig für die Serialisierung +compiler.warn.lint.serial.method.unexpected.return.type=Serialisierungsbezogene Methode {0} wurde mit dem Rückgabetyp {1} und nicht dem erwarteten Typ {2} deklariert.\nMit dieser Deklaration ist die Methode ungültig für die Serialisierung # 0: name, 1: type -compiler.warn.serial.method.unexpected.exception=Serialisierungsbezogene Methode {0} wurde zum Auslösen eines unerwarteten Typs {1} deklariert +compiler.warn.lint.serial.method.unexpected.exception=Serialisierungsbezogene Methode {0} wurde zum Auslösen eines unerwarteten Typs {1} deklariert compiler.warn.ineffectual.serial.field.interface=serialPersistentFields ist in einer Schnittstelle nicht effektiv diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_ja.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_ja.properties index 818b5fb70668b..089f1b02211db 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_ja.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_ja.properties @@ -1414,31 +1414,31 @@ compiler.warn.OSF.array.SPF=serialPersistentFieldsを有効にするには、タ compiler.warn.missing.SVUID=直列化可能なクラス{0}には、serialVersionUIDが定義されていません # 0: name -compiler.warn.serializable.missing.access.no.arg.ctor=シリアライズ不可のスーパークラス{0}で引数なしのコンストラクタにアクセスできません +compiler.warn.lint.serializable.missing.access.no.arg.ctor=シリアライズ不可のスーパークラス{0}で引数なしのコンストラクタにアクセスできません # 0: name -compiler.warn.serial.method.not.private=シリアライズ関連メソッド{0}はprivateとして宣言されていません +compiler.warn.lint.serial.method.not.private=シリアライズ関連メソッド{0}はprivateとして宣言されていません # 0: name -compiler.warn.serial.concrete.instance.method=シリアライズ関連メソッド{0}を有効にするには、concreteインスタンス・メソッドである必要があります。abstractでもstaticでもありません +compiler.warn.lint.serial.concrete.instance.method=シリアライズ関連メソッド{0}を有効にするには、concreteインスタンス・メソッドである必要があります。abstractでもstaticでもありません # 0: name -compiler.warn.serial.method.static=シリアライズ関連メソッド{0}がstaticとして宣言されています。有効にするには、かわりにインスタンス・メソッドにする必要があります +compiler.warn.lint.serial.method.static=シリアライズ関連メソッド{0}がstaticとして宣言されています。有効にするには、かわりにインスタンス・メソッドにする必要があります # 0: name -compiler.warn.serial.method.no.args=有効にするには、シリアライズ関連メソッド{0}にパラメータを指定しないでください +compiler.warn.lint.serial.method.no.args=有効にするには、シリアライズ関連メソッド{0}にパラメータを指定しないでください # 0: name, 1: number -compiler.warn.serial.method.one.arg=有効にするには、シリアライズ関連メソッド{0}に、{1}のパラメータではなく、パラメータを1つのみ指定する必要があります +compiler.warn.lint.serial.method.one.arg=有効にするには、シリアライズ関連メソッド{0}に、{1}のパラメータではなく、パラメータを1つのみ指定する必要があります # 0: name, 1: type, 2: type -compiler.warn.serial.method.parameter.type=有効にするには、シリアライズ関連メソッド{0}の1つのパラメータに、型{2}ではなく、型{1}を指定する必要があります +compiler.warn.lint.serial.method.parameter.type=有効にするには、シリアライズ関連メソッド{0}の1つのパラメータに、型{2}ではなく、型{1}を指定する必要があります # 0: name, 1: type, 2: type -compiler.warn.serial.method.unexpected.return.type=シリアライズ関連メソッド{0}は、必要な型{2}ではなく、{1}の戻り型で宣言されています。\n宣言されているように、メソッドはシリアライズが無効になります +compiler.warn.lint.serial.method.unexpected.return.type=シリアライズ関連メソッド{0}は、必要な型{2}ではなく、{1}の戻り型で宣言されています。\n宣言されているように、メソッドはシリアライズが無効になります # 0: name, 1: type -compiler.warn.serial.method.unexpected.exception=シリアライズ関連メソッド{0}は予期しない型{1}をスローするように宣言されています +compiler.warn.lint.serial.method.unexpected.exception=シリアライズ関連メソッド{0}は予期しない型{1}をスローするように宣言されています compiler.warn.ineffectual.serial.field.interface=serialPersistentFieldsはインタフェースで有効ではありません diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_zh_CN.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_zh_CN.properties index 54298cb23b912..9f9b49159c54e 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_zh_CN.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_zh_CN.properties @@ -1414,31 +1414,31 @@ compiler.warn.OSF.array.SPF=serialPersistentFields 的类型必须为 java.io.Ob compiler.warn.missing.SVUID=可序列化类{0}没有 serialVersionUID 的定义 # 0: name -compiler.warn.serializable.missing.access.no.arg.ctor=无法访问第一个不可序列化超类 {0} 中的无参数构造器 +compiler.warn.lint.serializable.missing.access.no.arg.ctor=无法访问第一个不可序列化超类 {0} 中的无参数构造器 # 0: name -compiler.warn.serial.method.not.private=与序列化相关的方法 {0} 未声明为 private +compiler.warn.lint.serial.method.not.private=与序列化相关的方法 {0} 未声明为 private # 0: name -compiler.warn.serial.concrete.instance.method=与序列化相关的方法 {0} 必须是具体的实例方法才能生效,既不能是抽象方法也不能是静态方法 +compiler.warn.lint.serial.concrete.instance.method=与序列化相关的方法 {0} 必须是具体的实例方法才能生效,既不能是抽象方法也不能是静态方法 # 0: name -compiler.warn.serial.method.static=与序列化相关的方法 {0} 声明为 static;必须改为实例方法才能有效 +compiler.warn.lint.serial.method.static=与序列化相关的方法 {0} 声明为 static;必须改为实例方法才能有效 # 0: name -compiler.warn.serial.method.no.args=与序列化相关的方法 {0} 必须没有参数才能生效 +compiler.warn.lint.serial.method.no.args=与序列化相关的方法 {0} 必须没有参数才能生效 # 0: name, 1: number -compiler.warn.serial.method.one.arg=与序列化相关的方法 {0} 必须只有一个参数(而非 {1} 个参数)才能生效 +compiler.warn.lint.serial.method.one.arg=与序列化相关的方法 {0} 必须只有一个参数(而非 {1} 个参数)才能生效 # 0: name, 1: type, 2: type -compiler.warn.serial.method.parameter.type=与序列化相关的方法 {0} 的唯一参数的类型必须为 {1}(而非 {2})才能生效 +compiler.warn.lint.serial.method.parameter.type=与序列化相关的方法 {0} 的唯一参数的类型必须为 {1}(而非 {2})才能生效 # 0: name, 1: type, 2: type -compiler.warn.serial.method.unexpected.return.type=与序列化相关的方法 {0} 是用返回类型 {1}(而不是预期类型 {2})声明的。\n如声明的那样,该方法对序列化无效 +compiler.warn.lint.serial.method.unexpected.return.type=与序列化相关的方法 {0} 是用返回类型 {1}(而不是预期类型 {2})声明的。\n如声明的那样,该方法对序列化无效 # 0: name, 1: type -compiler.warn.serial.method.unexpected.exception=与序列化相关的方法 {0} 声明为抛出意外类型 {1} +compiler.warn.lint.serial.method.unexpected.exception=与序列化相关的方法 {0} 声明为抛出意外类型 {1} compiler.warn.ineffectual.serial.field.interface=serialPersistentFields 在接口中无效 diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java index d303b5f710f05..84c0f4d933a4f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java @@ -29,7 +29,6 @@ import java.util.Map; import javax.tools.JavaFileObject; -import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; import com.sun.tools.javac.util.JCDiagnostic.Error; import com.sun.tools.javac.util.JCDiagnostic.Note; @@ -160,16 +159,7 @@ public void error(DiagnosticFlag flag, int pos, Error errorKey) { * @param warningKey The key for the localized warning message. */ public void warning(Warning warningKey) { - report(diags.warning(null, source, null, warningKey)); - } - - /** Report a lint warning, unless suppressed by the -nowarn option or the - * maximum number of warnings has been reached. - * @param lc The lint category for the diagnostic - * @param warningKey The key for the localized warning message. - */ - public void warning(LintCategory lc, Warning warningKey) { - report(diags.warning(lc, null, null, warningKey)); + report(diags.warning(source, null, warningKey)); } /** Report a warning, unless suppressed by the -nowarn option or the @@ -178,17 +168,7 @@ public void warning(LintCategory lc, Warning warningKey) { * @param warningKey The key for the localized warning message. */ public void warning(DiagnosticPosition pos, Warning warningKey) { - report(diags.warning(null, source, pos, warningKey)); - } - - /** Report a lint warning, unless suppressed by the -nowarn option or the - * maximum number of warnings has been reached. - * @param lc The lint category for the diagnostic - * @param pos The source position at which to report the warning. - * @param warningKey The key for the localized warning message. - */ - public void warning(LintCategory lc, DiagnosticPosition pos, Warning warningKey) { - report(diags.warning(lc, source, pos, warningKey)); + report(diags.warning(source, pos, warningKey)); } /** Report a warning, unless suppressed by the -nowarn option or the @@ -197,7 +177,7 @@ public void warning(LintCategory lc, DiagnosticPosition pos, Warning warningKey) * @param warningKey The key for the localized warning message. */ public void warning(int pos, Warning warningKey) { - report(diags.warning(null, source, wrap(pos), warningKey)); + report(diags.warning(source, wrap(pos), warningKey)); } /** Report a warning. @@ -205,16 +185,7 @@ public void warning(int pos, Warning warningKey) { * @param warningKey The key for the localized warning message. */ public void mandatoryWarning(DiagnosticPosition pos, Warning warningKey) { - report(diags.mandatoryWarning(null, source, pos, warningKey)); - } - - /** Report a warning. - * @param lc The lint category for the diagnostic - * @param pos The source position at which to report the warning. - * @param warningKey The key for the localized warning message. - */ - public void mandatoryWarning(LintCategory lc, DiagnosticPosition pos, Warning warningKey) { - report(diags.mandatoryWarning(lc, source, pos, warningKey)); + report(diags.mandatoryWarning(source, pos, warningKey)); } /** Provide a non-fatal notification, unless suppressed by the -nowarn option. diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java index 3f779175540fc..3d03845637640 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java @@ -111,7 +111,7 @@ public JCDiagnostic error( */ public JCDiagnostic error( DiagnosticFlag flag, DiagnosticSource source, DiagnosticPosition pos, Error errorKey) { - JCDiagnostic diag = create(null, EnumSet.copyOf(defaultErrorFlags), source, pos, errorKey); + JCDiagnostic diag = create(EnumSet.copyOf(defaultErrorFlags), source, pos, errorKey); if (flag != null) { diag.setFlag(flag); } @@ -130,21 +130,19 @@ public JCDiagnostic error( public JCDiagnostic mandatoryWarning( LintCategory lc, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { - return mandatoryWarning(lc, source, pos, warningKey(key, args)); + return mandatoryWarning(source, pos, warningKey(lc, key, args)); } /** * Create a warning diagnostic that will not be hidden by the -nowarn or -Xlint:none options. - * @param lc The lint category for the diagnostic * @param source The source of the compilation unit, if any, in which to report the warning. * @param pos The source position at which to report the warning. * @param warningKey The key for the localized warning message. * @see MandatoryWarningHandler */ public JCDiagnostic mandatoryWarning( - LintCategory lc, DiagnosticSource source, DiagnosticPosition pos, Warning warningKey) { - return create(lc, EnumSet.of(DiagnosticFlag.MANDATORY), source, pos, warningKey); + return create(EnumSet.of(DiagnosticFlag.MANDATORY), source, pos, warningKey); } /** @@ -158,20 +156,19 @@ public JCDiagnostic mandatoryWarning( */ public JCDiagnostic warning( LintCategory lc, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { - return warning(lc, source, pos, warningKey(key, args)); + return warning(source, pos, warningKey(lc, key, args)); } /** * Create a warning diagnostic. - * @param lc The lint category for the diagnostic * @param source The source of the compilation unit, if any, in which to report the warning. * @param pos The source position at which to report the warning. * @param warningKey The key for the localized warning message. * @see MandatoryWarningHandler */ public JCDiagnostic warning( - LintCategory lc, DiagnosticSource source, DiagnosticPosition pos, Warning warningKey) { - return create(lc, EnumSet.noneOf(DiagnosticFlag.class), source, pos, warningKey); + DiagnosticSource source, DiagnosticPosition pos, Warning warningKey) { + return create(EnumSet.noneOf(DiagnosticFlag.class), source, pos, warningKey); } /** @@ -191,7 +188,7 @@ public JCDiagnostic mandatoryNote(DiagnosticSource source, String key, Object... * @see MandatoryWarningHandler */ public JCDiagnostic mandatoryNote(DiagnosticSource source, Note noteKey) { - return create(null, EnumSet.of(DiagnosticFlag.MANDATORY), source, null, noteKey); + return create(EnumSet.of(DiagnosticFlag.MANDATORY), source, null, noteKey); } /** @@ -212,7 +209,7 @@ public JCDiagnostic note( */ public JCDiagnostic note( DiagnosticSource source, DiagnosticPosition pos, Note noteKey) { - return create(null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, noteKey); + return create(EnumSet.noneOf(DiagnosticFlag.class), source, pos, noteKey); } /** @@ -229,7 +226,7 @@ public JCDiagnostic fragment(String key, Object... args) { * @param fragmentKey The key for the localized subdiagnostic message. */ public JCDiagnostic fragment(Fragment fragmentKey) { - return create(null, EnumSet.noneOf(DiagnosticFlag.class), null, null, fragmentKey); + return create(EnumSet.noneOf(DiagnosticFlag.class), null, null, fragmentKey); } /** @@ -243,7 +240,7 @@ public JCDiagnostic fragment(Fragment fragmentKey) { */ public JCDiagnostic create( DiagnosticType kind, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { - return create(null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, DiagnosticInfo.of(kind, prefix, key, args)); + return create(EnumSet.noneOf(DiagnosticFlag.class), source, pos, DiagnosticInfo.of(kind, prefix, key, args)); } /** @@ -258,7 +255,7 @@ public JCDiagnostic create( */ public JCDiagnostic create( DiagnosticType kind, DiagnosticSource source, DiagnosticPosition pos, String key, UnaryOperator rewriter, Object... args) { - return create(null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, DiagnosticInfo.of(kind, prefix, key, args), rewriter); + return create(EnumSet.noneOf(DiagnosticFlag.class), source, pos, DiagnosticInfo.of(kind, prefix, key, args), rewriter); } /** @@ -270,7 +267,7 @@ public JCDiagnostic create( */ public JCDiagnostic create( DiagnosticSource source, DiagnosticPosition pos, DiagnosticInfo diagnosticInfo) { - return create(null, EnumSet.noneOf(DiagnosticFlag.class), source, pos, diagnosticInfo); + return create(EnumSet.noneOf(DiagnosticFlag.class), source, pos, diagnosticInfo); } /** @@ -285,25 +282,24 @@ public JCDiagnostic create( */ public JCDiagnostic create(DiagnosticType kind, LintCategory lc, Set flags, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { - return create(lc, flags, source, pos, DiagnosticInfo.of(kind, prefix, key, args)); + return create(flags, source, pos, DiagnosticInfo.of(kind, lc, prefix, key, args)); } /** * Create a new diagnostic with given key. - * @param lc The lint category, if applicable, or null * @param flags The set of flags for the diagnostic * @param source The source of the compilation unit, if any, in which to report the message. * @param pos The source position at which to report the message. * @param diagnosticInfo The key for the localized message. */ public JCDiagnostic create( - LintCategory lc, Set flags, DiagnosticSource source, DiagnosticPosition pos, DiagnosticInfo diagnosticInfo) { - return new JCDiagnostic(formatter, normalize(diagnosticInfo), lc, flags, source, pos); + Set flags, DiagnosticSource source, DiagnosticPosition pos, DiagnosticInfo diagnosticInfo) { + return new JCDiagnostic(formatter, normalize(diagnosticInfo), flags, source, pos); } public JCDiagnostic create( - LintCategory lc, Set flags, DiagnosticSource source, DiagnosticPosition pos, DiagnosticInfo diagnosticInfo, UnaryOperator rewriter) { - return new JCDiagnostic(formatter, normalize(diagnosticInfo), lc, flags, source, pos, rewriter); + Set flags, DiagnosticSource source, DiagnosticPosition pos, DiagnosticInfo diagnosticInfo, UnaryOperator rewriter) { + return new JCDiagnostic(formatter, normalize(diagnosticInfo), flags, source, pos, rewriter); } //where DiagnosticInfo normalize(DiagnosticInfo diagnosticInfo) { @@ -325,8 +321,8 @@ public Error errorKey(String code, Object... args) { /** * Create a new warning key. */ - Warning warningKey(String code, Object... args) { - return (Warning)DiagnosticInfo.of(WARNING, prefix, code, args); + Warning warningKey(LintCategory lintCategory, String code, Object... args) { + return (Warning)DiagnosticInfo.of(WARNING, lintCategory, prefix, code, args); } /** @@ -356,10 +352,10 @@ Fragment fragmentKey(String code, Object... args) { public static JCDiagnostic fragment(String key, Object... args) { return new JCDiagnostic(getFragmentFormatter(), DiagnosticInfo.of(FRAGMENT, + null, "compiler", key, args), - null, EnumSet.noneOf(DiagnosticFlag.class), null, null); @@ -464,7 +460,6 @@ public enum DiagnosticFlag { private final DiagnosticPosition position; private final DiagnosticInfo diagnosticInfo; private final Set flags; - private final LintCategory lintCategory; /** source line position (set lazily) */ private SourcePosition sourcePosition; @@ -537,11 +532,17 @@ public String key() { * Static factory method; build a custom diagnostic key using given kind, prefix, code and args. */ public static DiagnosticInfo of(DiagnosticType type, String prefix, String code, Object... args) { + return of(type, prefix, code, args); + } + + public static DiagnosticInfo of(DiagnosticType type, LintCategory lc, String prefix, String code, Object... args) { switch (type) { case ERROR: return new Error(prefix, code, args); case WARNING: - return new Warning(prefix, code, args); + return lc == null ? + new Warning(prefix, code, args) : + new LintWarning(prefix, lc, code, args); case NOTE: return new Note(prefix, code, args); case FRAGMENT: @@ -583,12 +584,28 @@ public Error(String prefix, String key, Object... args) { /** * Class representing warning diagnostic keys. */ - public static final class Warning extends DiagnosticInfo { + public static sealed class Warning extends DiagnosticInfo { public Warning(String prefix, String key, Object... args) { super(DiagnosticType.WARNING, prefix, key, args); } } + /** + * Class representing lint warning diagnostic keys. + */ + public static final class LintWarning extends Warning { + final LintCategory category; + + public LintWarning(String prefix, LintCategory lintCategory, String key, Object... args) { + super(prefix, key, args); + category = lintCategory; + } + + public LintWarning(String prefix, String key, Object... args) { + this(prefix, LintCategory.get(key.split("\\.")[2]), key, args); + } + } + /** * Class representing note diagnostic keys. */ @@ -614,31 +631,27 @@ public record AnnotatedType(Type type) {} * Create a diagnostic object. * @param formatter the formatter to use for the diagnostic * @param diagnosticInfo the diagnostic key - * @param lc the lint category for the diagnostic * @param source the name of the source file, or null if none. * @param pos the character offset within the source file, if given. */ protected JCDiagnostic(DiagnosticFormatter formatter, DiagnosticInfo diagnosticInfo, - LintCategory lc, Set flags, DiagnosticSource source, DiagnosticPosition pos) { - this(formatter, diagnosticInfo, lc, flags, source, pos, null); + this(formatter, diagnosticInfo, flags, source, pos, null); } /** * Create a diagnostic object. * @param formatter the formatter to use for the diagnostic * @param diagnosticInfo the diagnostic key - * @param lc the lint category for the diagnostic * @param source the name of the source file, or null if none. * @param pos the character offset within the source file, if given. * @param rewriter the rewriter function used if this diagnostic needs to be rewritten */ protected JCDiagnostic(DiagnosticFormatter formatter, DiagnosticInfo diagnosticInfo, - LintCategory lc, Set flags, DiagnosticSource source, DiagnosticPosition pos, @@ -648,7 +661,6 @@ protected JCDiagnostic(DiagnosticFormatter formatter, this.defaultFormatter = formatter; this.diagnosticInfo = diagnosticInfo; - this.lintCategory = lc; this.flags = flags; this.source = source; this.position = pos; @@ -687,14 +699,15 @@ public boolean isMandatory() { * Check whether this diagnostic has an associated lint category. */ public boolean hasLintCategory() { - return (lintCategory != null); + return diagnosticInfo instanceof LintWarning; } /** * Get the associated lint category, or null if none. */ public LintCategory getLintCategory() { - return lintCategory; + return diagnosticInfo instanceof LintWarning lintWarning ? + lintWarning.category : null; } /** @@ -870,7 +883,6 @@ public static class MultilineDiagnostic extends JCDiagnostic { public MultilineDiagnostic(JCDiagnostic other, List subdiagnostics) { super(other.defaultFormatter, other.diagnosticInfo, - other.getLintCategory(), other.flags, other.getDiagnosticSource(), other.position); diff --git a/test/langtools/tools/javac/diags/examples/SerialMissingNoArgCtor.java b/test/langtools/tools/javac/diags/examples/SerialMissingNoArgCtor.java index 0bb028a69a66f..8d9b4964ee392 100644 --- a/test/langtools/tools/javac/diags/examples/SerialMissingNoArgCtor.java +++ b/test/langtools/tools/javac/diags/examples/SerialMissingNoArgCtor.java @@ -21,7 +21,7 @@ * questions. */ -// key: compiler.warn.serializable.missing.access.no.arg.ctor +// key: compiler.warn.lint.serializable.missing.access.no.arg.ctor // key: compiler.warn.non.serializable.instance.field // key: compiler.warn.non.serializable.instance.field.array diff --git a/test/langtools/tools/javac/diags/examples/SerialNonPrivateMethod.java b/test/langtools/tools/javac/diags/examples/SerialNonPrivateMethod.java index 45f3273117b85..0bdabb8bb0330 100644 --- a/test/langtools/tools/javac/diags/examples/SerialNonPrivateMethod.java +++ b/test/langtools/tools/javac/diags/examples/SerialNonPrivateMethod.java @@ -21,14 +21,14 @@ * questions. */ -// key: compiler.warn.serial.method.not.private -// key: compiler.warn.serial.method.static -// key: compiler.warn.serial.method.unexpected.return.type -// key: compiler.warn.serial.concrete.instance.method -// key: compiler.warn.serial.method.one.arg -// key: compiler.warn.serial.method.parameter.type -// key: compiler.warn.serial.method.no.args -// key: compiler.warn.serial.method.unexpected.exception +// key: compiler.warn.lint.serial.method.not.private +// key: compiler.warn.lint.serial.method.static +// key: compiler.warn.lint.serial.method.unexpected.return.type +// key: compiler.warn.lint.serial.concrete.instance.method +// key: compiler.warn.lint.serial.method.one.arg +// key: compiler.warn.lint.serial.method.parameter.type +// key: compiler.warn.lint.serial.method.no.args +// key: compiler.warn.lint.serial.method.unexpected.exception // options: -Xlint:serial diff --git a/test/langtools/tools/javac/warnings/Serial/CtorAccess.out b/test/langtools/tools/javac/warnings/Serial/CtorAccess.out index c271e8779f8b3..380fdda80ba88 100644 --- a/test/langtools/tools/javac/warnings/Serial/CtorAccess.out +++ b/test/langtools/tools/javac/warnings/Serial/CtorAccess.out @@ -1,3 +1,3 @@ -CtorAccess.java:16:12: compiler.warn.serializable.missing.access.no.arg.ctor: CtorAccess -CtorAccess.java:31:5: compiler.warn.serializable.missing.access.no.arg.ctor: CtorAccess.MemberSuper +CtorAccess.java:16:12: compiler.warn.lint.serializable.missing.access.no.arg.ctor: CtorAccess +CtorAccess.java:31:5: compiler.warn.lint.serializable.missing.access.no.arg.ctor: CtorAccess.MemberSuper 2 warnings diff --git a/test/langtools/tools/javac/warnings/Serial/ImproperReturnTypes.out b/test/langtools/tools/javac/warnings/Serial/ImproperReturnTypes.out index df5c0456d471a..7891a6daa17c3 100644 --- a/test/langtools/tools/javac/warnings/Serial/ImproperReturnTypes.out +++ b/test/langtools/tools/javac/warnings/Serial/ImproperReturnTypes.out @@ -1,6 +1,6 @@ -ImproperReturnTypes.java:24:17: compiler.warn.serial.method.unexpected.return.type: writeObject, int, void -ImproperReturnTypes.java:29:17: compiler.warn.serial.method.unexpected.return.type: writeReplace, int, java.lang.Object -ImproperReturnTypes.java:33:17: compiler.warn.serial.method.unexpected.return.type: readObject, int, void -ImproperReturnTypes.java:39:17: compiler.warn.serial.method.unexpected.return.type: readObjectNoData, int, void -ImproperReturnTypes.java:43:17: compiler.warn.serial.method.unexpected.return.type: readResolve, int, java.lang.Object +ImproperReturnTypes.java:24:17: compiler.warn.lint.serial.method.unexpected.return.type: writeObject, int, void +ImproperReturnTypes.java:29:17: compiler.warn.lint.serial.method.unexpected.return.type: writeReplace, int, java.lang.Object +ImproperReturnTypes.java:33:17: compiler.warn.lint.serial.method.unexpected.return.type: readObject, int, void +ImproperReturnTypes.java:39:17: compiler.warn.lint.serial.method.unexpected.return.type: readObjectNoData, int, void +ImproperReturnTypes.java:43:17: compiler.warn.lint.serial.method.unexpected.return.type: readResolve, int, java.lang.Object 5 warnings diff --git a/test/langtools/tools/javac/warnings/Serial/SerialMethodArity.out b/test/langtools/tools/javac/warnings/Serial/SerialMethodArity.out index 66f1c65305f0e..620e0511bfa3f 100644 --- a/test/langtools/tools/javac/warnings/Serial/SerialMethodArity.out +++ b/test/langtools/tools/javac/warnings/Serial/SerialMethodArity.out @@ -1,6 +1,6 @@ -SerialMethodArity.java:18:18: compiler.warn.serial.method.parameter.type: writeObject, java.io.ObjectOutputStream, SerialMethodMods.CustomObjectOutputStream -SerialMethodArity.java:23:18: compiler.warn.serial.method.one.arg: readObject, 2 -SerialMethodArity.java:29:39: compiler.warn.serial.method.no.args: readObjectNoData -SerialMethodArity.java:32:36: compiler.warn.serial.method.no.args: writeReplace -SerialMethodArity.java:37:38: compiler.warn.serial.method.no.args: readResolve +SerialMethodArity.java:18:18: compiler.warn.lint.serial.method.parameter.type: writeObject, java.io.ObjectOutputStream, SerialMethodMods.CustomObjectOutputStream +SerialMethodArity.java:23:18: compiler.warn.lint.serial.method.one.arg: readObject, 2 +SerialMethodArity.java:29:39: compiler.warn.lint.serial.method.no.args: readObjectNoData +SerialMethodArity.java:32:36: compiler.warn.lint.serial.method.no.args: writeReplace +SerialMethodArity.java:37:38: compiler.warn.lint.serial.method.no.args: readResolve 5 warnings diff --git a/test/langtools/tools/javac/warnings/Serial/SerialMethodMods.out b/test/langtools/tools/javac/warnings/Serial/SerialMethodMods.out index 0f84b4cdf6e20..83cfb680c9260 100644 --- a/test/langtools/tools/javac/warnings/Serial/SerialMethodMods.out +++ b/test/langtools/tools/javac/warnings/Serial/SerialMethodMods.out @@ -1,6 +1,6 @@ -SerialMethodMods.java:13:10: compiler.warn.serial.method.not.private: writeObject -SerialMethodMods.java:18:17: compiler.warn.serial.method.not.private: readObject -SerialMethodMods.java:24:25: compiler.warn.serial.method.static: readObjectNoData -SerialMethodMods.java:27:28: compiler.warn.serial.concrete.instance.method: writeReplace -SerialMethodMods.java:30:26: compiler.warn.serial.concrete.instance.method: readResolve +SerialMethodMods.java:13:10: compiler.warn.lint.serial.method.not.private: writeObject +SerialMethodMods.java:18:17: compiler.warn.lint.serial.method.not.private: readObject +SerialMethodMods.java:24:25: compiler.warn.lint.serial.method.static: readObjectNoData +SerialMethodMods.java:27:28: compiler.warn.lint.serial.concrete.instance.method: writeReplace +SerialMethodMods.java:30:26: compiler.warn.lint.serial.concrete.instance.method: readResolve 5 warnings diff --git a/test/langtools/tools/javac/warnings/Serial/SerialMethodThrows.out b/test/langtools/tools/javac/warnings/Serial/SerialMethodThrows.out index fdb6765999bb3..0caedf0b9150a 100644 --- a/test/langtools/tools/javac/warnings/Serial/SerialMethodThrows.out +++ b/test/langtools/tools/javac/warnings/Serial/SerialMethodThrows.out @@ -1,6 +1,6 @@ -SerialMethodThrows.java:187:22: compiler.warn.serial.method.unexpected.exception: writeObject, SerialMethodThrows.CustomException -SerialMethodThrows.java:196:24: compiler.warn.serial.method.unexpected.exception: writeReplace, SerialMethodThrows.CustomException -SerialMethodThrows.java:201:22: compiler.warn.serial.method.unexpected.exception: readObject, SerialMethodThrows.CustomException -SerialMethodThrows.java:210:22: compiler.warn.serial.method.unexpected.exception: readObjectNoData, SerialMethodThrows.CustomException -SerialMethodThrows.java:213:24: compiler.warn.serial.method.unexpected.exception: readResolve, SerialMethodThrows.CustomException +SerialMethodThrows.java:187:22: compiler.warn.lint.serial.method.unexpected.exception: writeObject, SerialMethodThrows.CustomException +SerialMethodThrows.java:196:24: compiler.warn.lint.serial.method.unexpected.exception: writeReplace, SerialMethodThrows.CustomException +SerialMethodThrows.java:201:22: compiler.warn.lint.serial.method.unexpected.exception: readObject, SerialMethodThrows.CustomException +SerialMethodThrows.java:210:22: compiler.warn.lint.serial.method.unexpected.exception: readObjectNoData, SerialMethodThrows.CustomException +SerialMethodThrows.java:213:24: compiler.warn.lint.serial.method.unexpected.exception: readResolve, SerialMethodThrows.CustomException 5 warnings From b878483bc0027df831b453453e5f1e0f4f872b41 Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Fri, 29 Nov 2024 22:46:24 +0000 Subject: [PATCH 02/10] Builds ok --- .../propertiesparser/gen/ClassGenerator.java | 8 ++++- .../tools/javac/resources/compiler.properties | 14 ++++----- .../com/sun/tools/javac/util/AbstractLog.java | 29 +++++++++++++++++++ .../sun/tools/javac/util/JCDiagnostic.java | 16 +++++++--- 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/make/langtools/tools/propertiesparser/gen/ClassGenerator.java b/make/langtools/tools/propertiesparser/gen/ClassGenerator.java index e3ab548491b76..bac76879d45c5 100644 --- a/make/langtools/tools/propertiesparser/gen/ClassGenerator.java +++ b/make/langtools/tools/propertiesparser/gen/ClassGenerator.java @@ -239,7 +239,13 @@ List generateFactoryMethodsAndFields(String key, Message msg) { .collect(Collectors.joining("\n *")); String[] keyParts = key.split("\\."); FactoryKind k = FactoryKind.parseFrom(keyParts[1]); - String factoryName = factoryName(key); + String factoryName; + if (keyParts[2].equals("lint")) { + // skip lint warning category + factoryName = factoryName(key.replace(".lint." + keyParts[3], "")); + } else { + factoryName = factoryName(key); + } if (msgInfo.getTypes().isEmpty()) { //generate field String factoryField = StubKind.FACTORY_FIELD.format(k.keyClazz, factoryName, 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 c26a1b7f19955..2449b4b15e42d 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 @@ -1876,7 +1876,7 @@ compiler.warn.lintOption=\ compiler.warn.constant.SVUID=\ serialVersionUID must be constant in class {0} -compiler.warn.lint.dangling.dangling.doc.comments=\ +compiler.warn.lint.dangling.dangling.doc.comment=\ documentation comment is not attached to any declaration # 0: path @@ -1927,7 +1927,7 @@ compiler.warn.is.preview.reflective=\ {0} is a reflective preview API and may be removed in a future release. # 0: symbol, 1: symbol -compiler.warn.restricted.restricted.method=\ +compiler.warn.lint.restricted.restricted.method=\ {0}.{1} is a restricted method.\n\ (Restricted methods are unsafe and, if used incorrectly, might crash the Java runtime or corrupt memory) @@ -2096,7 +2096,7 @@ compiler.warn.pkg-info.already.seen=\ compiler.warn.lint.path.path.element.not.found=\ bad path element "{0}": no such file or directory -compiler.warn.fallthrough.possible.fall-through.into.case=\ +compiler.warn.lint.fallthrough.possible.fall-through.into.case=\ possible fall-through into case # 0: type @@ -2121,7 +2121,7 @@ compiler.warn.lint.static.static.not.qualified.by.type=\ static {0} should be qualified by type name, {1}, instead of by an expression # 0: kind name -compiler.warn..lint.static.static.not.qualified.by.type2=\ +compiler.warn.lint.static.static.not.qualified.by.type2=\ static {0} should not be used as a member of an anonymous class # 0: string, 1: fragment @@ -3171,15 +3171,15 @@ compiler.err.preview.feature.disabled.classfile=\ (use --enable-preview to allow loading of class files which contain preview features) # 0: message segment (feature) -compiler.warn.preview.preview.feature.use=\ +compiler.warn.lint.preview.preview.feature.use=\ {0} is a preview feature and may be removed in a future release. # 0: message segment (feature) -compiler.warn.preview.preview.feature.use.plural=\ +compiler.warn.lint.preview.preview.feature.use.plural=\ {0} are a preview feature and may be removed in a future release. # 0: file object (classfile), 1: string (expected version) -compiler.warn.preview.preview.feature.use.classfile=\ +compiler.warn.lint.preview.preview.feature.use.classfile=\ class file for {0} uses preview features of Java SE {1}. compiler.misc.feature.modules=\ diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java index 84c0f4d933a4f..27c994538ac8f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java @@ -29,6 +29,7 @@ import java.util.Map; import javax.tools.JavaFileObject; +import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; import com.sun.tools.javac.util.JCDiagnostic.Error; import com.sun.tools.javac.util.JCDiagnostic.Note; @@ -162,6 +163,15 @@ public void warning(Warning warningKey) { report(diags.warning(source, null, warningKey)); } + /** Report a lint warning, unless suppressed by the -nowarn option or the + * maximum number of warnings has been reached. + * @param lc The lint category for the diagnostic + * @param warningKey The key for the localized warning message. + */ + public void warning(LintCategory lc, Warning warningKey) { + report(diags.warning(null, null, warningKey)); + } + /** Report a warning, unless suppressed by the -nowarn option or the * maximum number of warnings has been reached. * @param pos The source position at which to report the warning. @@ -171,6 +181,16 @@ public void warning(DiagnosticPosition pos, Warning warningKey) { report(diags.warning(source, pos, warningKey)); } + /** Report a lint warning, unless suppressed by the -nowarn option or the + * maximum number of warnings has been reached. + * @param lc The lint category for the diagnostic + * @param pos The source position at which to report the warning. + * @param warningKey The key for the localized warning message. + */ + public void warning(LintCategory lc, DiagnosticPosition pos, Warning warningKey) { + report(diags.warning(source, pos, warningKey)); + } + /** Report a warning, unless suppressed by the -nowarn option or the * maximum number of warnings has been reached. * @param pos The source position at which to report the warning. @@ -188,6 +208,15 @@ public void mandatoryWarning(DiagnosticPosition pos, Warning warningKey) { report(diags.mandatoryWarning(source, pos, warningKey)); } + /** Report a warning. + * @param lc The lint category for the diagnostic + * @param pos The source position at which to report the warning. + * @param warningKey The key for the localized warning message. + */ + public void mandatoryWarning(LintCategory lc, DiagnosticPosition pos, Warning warningKey) { + report(diags.mandatoryWarning(source, pos, warningKey)); + } + /** Provide a non-fatal notification, unless suppressed by the -nowarn option. * @param noteKey The key for the localized notification message. */ diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java index 3d03845637640..0ee5f1138831f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java @@ -532,7 +532,7 @@ public String key() { * Static factory method; build a custom diagnostic key using given kind, prefix, code and args. */ public static DiagnosticInfo of(DiagnosticType type, String prefix, String code, Object... args) { - return of(type, prefix, code, args); + return of(type, null, prefix, code, args); } public static DiagnosticInfo of(DiagnosticType type, LintCategory lc, String prefix, String code, Object... args) { @@ -540,9 +540,7 @@ public static DiagnosticInfo of(DiagnosticType type, LintCategory lc, String pre case ERROR: return new Error(prefix, code, args); case WARNING: - return lc == null ? - new Warning(prefix, code, args) : - new LintWarning(prefix, lc, code, args); + return new Warning(lc, prefix, code, args); case NOTE: return new Note(prefix, code, args); case FRAGMENT: @@ -585,8 +583,18 @@ public Error(String prefix, String key, Object... args) { * Class representing warning diagnostic keys. */ public static sealed class Warning extends DiagnosticInfo { + final LintCategory category; + public Warning(String prefix, String key, Object... args) { super(DiagnosticType.WARNING, prefix, key, args); + category = key.contains(".lint.") ? + LintCategory.get(key.split("\\.")[2]) : + null; + } + + public Warning(LintCategory category, String prefix, String key, Object... args) { + super(DiagnosticType.WARNING, prefix, key, args); + this.category = category; } } From ad337b42c3a173c70be5874b0d3460fe7b44cde1 Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Mon, 2 Dec 2024 12:27:17 +0000 Subject: [PATCH 03/10] Use diagnostic info line to declare lint category --- .../propertiesparser/gen/ClassGenerator.java | 53 +++- .../propertiesparser/parser/Message.java | 5 +- .../propertiesparser/parser/MessageLine.java | 16 + .../resources/templates.properties | 12 + .../tools/javac/resources/compiler.properties | 297 ++++++++++++------ .../javac/resources/compiler_de.properties | 18 +- .../javac/resources/compiler_ja.properties | 18 +- .../javac/resources/compiler_zh_CN.properties | 18 +- .../sun/tools/javac/util/JCDiagnostic.java | 5 +- .../examples/SerialMissingNoArgCtor.java | 2 +- .../examples/SerialNonPrivateMethod.java | 16 +- .../javac/warnings/Serial/CtorAccess.out | 4 +- .../warnings/Serial/ImproperReturnTypes.out | 10 +- .../warnings/Serial/SerialMethodArity.out | 10 +- .../warnings/Serial/SerialMethodMods.out | 10 +- .../warnings/Serial/SerialMethodThrows.out | 10 +- 16 files changed, 326 insertions(+), 178 deletions(-) diff --git a/make/langtools/tools/propertiesparser/gen/ClassGenerator.java b/make/langtools/tools/propertiesparser/gen/ClassGenerator.java index bac76879d45c5..079d01cee1937 100644 --- a/make/langtools/tools/propertiesparser/gen/ClassGenerator.java +++ b/make/langtools/tools/propertiesparser/gen/ClassGenerator.java @@ -87,9 +87,12 @@ enum StubKind { FACTORY_METHOD_DECL("factory.decl.method"), FACTORY_METHOD_ARG("factory.decl.method.arg"), FACTORY_METHOD_BODY("factory.decl.method.body"), + FACTORY_METHOD_BODY_LINT("factory.decl.method.body.lint"), FACTORY_FIELD("factory.decl.field"), + FACTORY_FIELD_LINT("factory.decl.field.lint"), WILDCARDS_EXTENDS("wildcards.extends"), - SUPPRESS_WARNINGS("suppress.warnings"); + SUPPRESS_WARNINGS("suppress.warnings"), + LINT_CATEGORY("lint.category"); /** stub key (as it appears in the property file) */ String key; @@ -239,19 +242,27 @@ List generateFactoryMethodsAndFields(String key, Message msg) { .collect(Collectors.joining("\n *")); String[] keyParts = key.split("\\."); FactoryKind k = FactoryKind.parseFrom(keyParts[1]); - String factoryName; - if (keyParts[2].equals("lint")) { - // skip lint warning category - factoryName = factoryName(key.replace(".lint." + keyParts[3], "")); - } else { - factoryName = factoryName(key); - } + String lintCategory = lines.stream() + .filter(MessageLine::isLint) + .map(MessageLine::lintCategory) + .findFirst().orElse(null); + //System.out.println("category for " + key + " = " + lintCategory); + String factoryName = factoryName(key); if (msgInfo.getTypes().isEmpty()) { //generate field - String factoryField = StubKind.FACTORY_FIELD.format(k.keyClazz, factoryName, - "\"" + keyParts[0] + "\"", - "\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"", - javadoc); + String factoryField; + if (lintCategory == null) { + factoryField = StubKind.FACTORY_FIELD.format(k.keyClazz, factoryName, + "\"" + keyParts[0] + "\"", + "\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"", + javadoc); + } else { + factoryField = StubKind.FACTORY_FIELD_LINT.format(k.keyClazz, factoryName, + StubKind.LINT_CATEGORY.format("\"" + lintCategory + "\""), + "\"" + keyParts[0] + "\"", + "\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"", + javadoc); + } return Collections.singletonList(factoryField); } else { //generate method @@ -261,12 +272,22 @@ List generateFactoryMethodsAndFields(String key, Message msg) { List argNames = argNames(types.size()); String suppressionString = needsSuppressWarnings(msgTypes) ? StubKind.SUPPRESS_WARNINGS.format() : ""; + String methodBody; + if (lintCategory == null) { + methodBody = StubKind.FACTORY_METHOD_BODY.format(k.keyClazz, + "\"" + keyParts[0] + "\"", + "\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"", + argNames.stream().collect(Collectors.joining(", "))); + } else { + methodBody = StubKind.FACTORY_METHOD_BODY_LINT.format(k.keyClazz, + StubKind.LINT_CATEGORY.format("\"" + lintCategory + "\""), + "\"" + keyParts[0] + "\"", + "\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"", + argNames.stream().collect(Collectors.joining(", "))); + } String factoryMethod = StubKind.FACTORY_METHOD_DECL.format(suppressionString, k.keyClazz, factoryName, argDecls(types, argNames).stream().collect(Collectors.joining(", ")), - indent(StubKind.FACTORY_METHOD_BODY.format(k.keyClazz, - "\"" + keyParts[0] + "\"", - "\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"", - argNames.stream().collect(Collectors.joining(", "))), 1), + indent(methodBody, 1), javadoc); factoryMethods.add(factoryMethod); } diff --git a/make/langtools/tools/propertiesparser/parser/Message.java b/make/langtools/tools/propertiesparser/parser/Message.java index 02a2f5e4f5c75..3c1191084ec1c 100644 --- a/make/langtools/tools/propertiesparser/parser/Message.java +++ b/make/langtools/tools/propertiesparser/parser/Message.java @@ -49,6 +49,9 @@ public final class Message { public MessageInfo getMessageInfo() { if (messageInfo == null) { MessageLine l = firstLine.prev; + if (l != null && l.isLint()) { + l = l.prev; + } if (l != null && l.isInfo()) messageInfo = new MessageInfo(l.text); else @@ -71,7 +74,7 @@ public List getLines(boolean includeAllPrecedingComments) { while (l.text.isEmpty()) l = l.next; } else { - if (l.prev != null && l.prev.isInfo()) + if (l.prev != null && (l.prev.isInfo() || l.prev.isLint())) l = l.prev; } diff --git a/make/langtools/tools/propertiesparser/parser/MessageLine.java b/make/langtools/tools/propertiesparser/parser/MessageLine.java index e370eefa38a82..559b5c60f6497 100644 --- a/make/langtools/tools/propertiesparser/parser/MessageLine.java +++ b/make/langtools/tools/propertiesparser/parser/MessageLine.java @@ -25,6 +25,8 @@ package propertiesparser.parser; +import java.util.Optional; +import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -37,6 +39,7 @@ public class MessageLine { static final Pattern typePattern = Pattern.compile("[-\\\\'A-Z\\.a-z ]+( \\([-A-Za-z 0-9]+\\))?"); static final Pattern infoPattern = Pattern.compile(String.format("# ([0-9]+: %s, )*[0-9]+: %s", typePattern.pattern(), typePattern.pattern())); + static final Pattern lintPattern = Pattern.compile("# lint: ([a-z\\-]+)"); public String text; MessageLine prev; @@ -54,6 +57,19 @@ public boolean isInfo() { return infoPattern.matcher(text).matches(); } + public boolean isLint() { + return lintPattern.matcher(text).matches(); + } + + public String lintCategory() { + Matcher matcher = lintPattern.matcher(text); + if (matcher.matches()) { + return matcher.group(1); + } else { + return null; + } + } + boolean hasContinuation() { return (next != null) && text.endsWith("\\"); } diff --git a/make/langtools/tools/propertiesparser/resources/templates.properties b/make/langtools/tools/propertiesparser/resources/templates.properties index b6685e688912e..44f6248cf0040 100644 --- a/make/langtools/tools/propertiesparser/resources/templates.properties +++ b/make/langtools/tools/propertiesparser/resources/templates.properties @@ -31,6 +31,7 @@ toplevel.decl=\ import com.sun.tools.javac.util.JCDiagnostic.Warning;\n\ import com.sun.tools.javac.util.JCDiagnostic.Note;\n\ import com.sun.tools.javac.util.JCDiagnostic.Fragment;\n\ + import com.sun.tools.javac.code.Lint.LintCategory;\n\ \n\ public class {2} '{'\n\ {3}\n\ @@ -58,16 +59,27 @@ factory.decl.method.arg=\ factory.decl.method.body=\ return new {0}({1}, {2}, {3}); +factory.decl.method.body.lint=\ + return new {0}({1}, {2}, {3}, {4}); + factory.decl.field=\ /**\n\ ' '* {4}\n\ ' '*/\n\ public static final {0} {1} = new {0}({2}, {3}); +factory.decl.field.lint=\ + /**\n\ + ' '* {5}\n\ + ' '*/\n\ + public static final {0} {1} = new {0}({2}, {3}, {4}); + wildcards.extends=\ {0} suppress.warnings=\ @SuppressWarnings("rawtypes")\n +lint.category=\ + LintCategory.get({0}) 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 2449b4b15e42d..ee1d197412651 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 @@ -708,10 +708,12 @@ compiler.err.not.in.profile=\ compiler.warn.forward.ref=\ reference to variable ''{0}'' before it has been initialized -compiler.warn.lint.this-escape.possible.this.escape=\ +# lint: this-escape +compiler.warn.possible.this.escape=\ possible ''this'' escape before subclass is fully initialized -compiler.warn.lint.this-escape.possible.this.escape.location=\ +# lint: this-escape +compiler.warn.possible.this.escape.location=\ previous possible ''this'' escape happens here via invocation compiler.err.illegal.self.ref=\ @@ -731,10 +733,12 @@ compiler.err.illegal.line.end.in.char.lit=\ compiler.err.illegal.text.block.open=\ illegal text block open delimiter sequence, missing line terminator -compiler.warn.lint.text-blocks.inconsistent.white.space.indentation=\ +# lint: text-blocks +compiler.warn.inconsistent.white.space.indentation=\ inconsistent white space indentation -compiler.warn.lint.text-blocks.trailing.white.space.will.be.removed=\ +# lint: text-blocks +compiler.warn.trailing.white.space.will.be.removed=\ trailing white space will be removed compiler.err.illegal.nonascii.digit=\ @@ -1594,7 +1598,8 @@ compiler.err.multi-module.outdir.cannot.be.exploded.module=\ in multi-module mode, the output directory cannot be an exploded module: {0} # 0: path -compiler.warn.lint.path.outdir.is.in.exploded.module=\ +# lint: path +compiler.warn.outdir.is.in.exploded.module=\ the output directory is within an exploded module: {0} # 0: file object @@ -1661,7 +1666,8 @@ compiler.warn.file.from.future=\ Modification date is in the future for file {0} # 0: path -compiler.warn.lint.output-file-clash.output.file.clash=\ +# lint: output-file-clash +compiler.warn.output.file.clash=\ output file written more than once: {0} ##### @@ -1876,41 +1882,51 @@ compiler.warn.lintOption=\ compiler.warn.constant.SVUID=\ serialVersionUID must be constant in class {0} -compiler.warn.lint.dangling.dangling.doc.comment=\ +# lint: dangling +compiler.warn.dangling.doc.comment=\ documentation comment is not attached to any declaration # 0: path -compiler.warn.lint.path.dir.path.element.not.found=\ +# lint: path +compiler.warn.dir.path.element.not.found=\ bad path element "{0}": no such directory # 0: file name -compiler.warn.lint.path.dir.path.element.not.directory=\ +# lint: path +compiler.warn.dir.path.element.not.directory=\ bad path element "{0}": not a directory # 0: symbol, 1: symbol, 2: symbol -compiler.warn.lint.missing-explicit-ctor.missing.explicit.ctor=\ +# lint: missing-explicit-ctor +compiler.warn.missing.explicit.ctor=\ class {0} in exported package {1} declares no explicit constructors, thereby exposing a default constructor to clients of module {2} -compiler.warn.lint.strictfp.strictfp=\ +# lint: strictfp +compiler.warn.strictfp=\ as of release 17, all floating-point expressions are evaluated strictly and ''strictfp'' is not required -compiler.warn.lint.finally.finally.cannot.complete=\ +# lint: finally +compiler.warn.finally.cannot.complete=\ finally clause cannot complete normally # 0: name -compiler.warn.lint.module.poor.choice.for.module.name=\ +# lint: module +compiler.warn.poor.choice.for.module.name=\ module name component {0} should avoid terminal digits # 0: string -compiler.warn.lint.incubating.incubating.modules=\ +# lint: incubating +compiler.warn.incubating.modules=\ using incubating module(s): {0} # 0: symbol, 1: symbol -compiler.warn.lint.deprecation.has.been.deprecated=\ +# lint: deprecation +compiler.warn.has.been.deprecated=\ {0} in {1} has been deprecated # 0: symbol, 1: symbol -compiler.warn.lint.removal.has.been.deprecated.for.removal=\ +# lint: removal +compiler.warn.has.been.deprecated.for.removal=\ {0} in {1} has been deprecated and marked for removal # 0: symbol @@ -1927,16 +1943,19 @@ compiler.warn.is.preview.reflective=\ {0} is a reflective preview API and may be removed in a future release. # 0: symbol, 1: symbol -compiler.warn.lint.restricted.restricted.method=\ +# lint: restricted +compiler.warn.restricted.method=\ {0}.{1} is a restricted method.\n\ (Restricted methods are unsafe and, if used incorrectly, might crash the Java runtime or corrupt memory) # 0: symbol -compiler.warn.lint.deprecation.has.been.deprecated.module=\ +# lint: deprecation +compiler.warn.has.been.deprecated.module=\ module {0} has been deprecated # 0: symbol -compiler.warn.lint.removal.has.been.deprecated.for.removal.module=\ +# lint: removal +compiler.warn.has.been.deprecated.for.removal.module=\ module {0} has been deprecated and marked for removal # 0: symbol @@ -1990,36 +2009,44 @@ compiler.warn.serializable.missing.access.no.arg.ctor=\ cannot access a no-arg constructor in first non-serializable superclass {0} # 0: name -compiler.warn.lint.serial.serial.method.not.private=\ +# lint: serial +compiler.warn.serial.method.not.private=\ serialization-related method {0} not declared private # 0: name -compiler.warn.lint.serial.serial.concrete.instance.method=\ +# lint: serial +compiler.warn.serial.concrete.instance.method=\ serialization-related method {0} must be a concrete instance method to be effective, neither abstract nor static # 0: name -compiler.warn.lint.serial.serial.method.static=\ +# lint: serial +compiler.warn.serial.method.static=\ serialization-related method {0} declared static; must instead be an instance method to be effective # 0: name -compiler.warn.lint.serial.serial.method.no.args=\ +# lint: serial +compiler.warn.serial.method.no.args=\ to be effective serialization-related method {0} must have no parameters # 0: name, 1: number -compiler.warn.lint.serial.serial.method.one.arg=\ +# lint: serial +compiler.warn.serial.method.one.arg=\ to be effective serialization-related method {0} must have exactly one parameter rather than {1} parameters # 0: name, 1: type, 2: type -compiler.warn.lint.serial.serial.method.parameter.type=\ +# lint: serial +compiler.warn.serial.method.parameter.type=\ sole parameter of serialization-related method {0} must have type {1} to be effective rather than type {2} # 0: name, 1: type, 2: type -compiler.warn.lint.serial.serial.method.unexpected.return.type=\ +# lint: serial +compiler.warn.serial.method.unexpected.return.type=\ serialization-related method {0} declared with a return type of {1} rather than expected type {2}.\n\ As declared, the method will be ineffective for serialization # 0: name, 1: type -compiler.warn.lint.serial.serial.method.unexpected.exception=\ +# lint: serial +compiler.warn.serial.method.unexpected.exception=\ serialization-related method {0} declared to throw an unexpected type {1} compiler.warn.ineffectual.serial.field.interface=\ @@ -2073,15 +2100,18 @@ compiler.warn.default.ineffective=\ serialization-related default method from an interface will not be run by serialization for an implementing class # 0: symbol, 1: symbol, 2: symbol, 3: symbol -compiler.warn.lint.overloads.potentially.ambiguous.overload=\ +# lint: overloads +compiler.warn.potentially.ambiguous.overload=\ {0} in {1} is potentially ambiguous with {2} in {3} # 0: message segment -compiler.warn.lint.overrides.override.varargs.missing=\ +# lint: overrides +compiler.warn.override.varargs.missing=\ {0}; overridden method has no ''...'' # 0: message segment -compiler.warn.lint.overrides.override.varargs.extra=\ +# lint: overrides +compiler.warn.override.varargs.extra=\ {0}; overriding method is missing ''...'' # 0: message segment @@ -2093,14 +2123,17 @@ compiler.warn.pkg-info.already.seen=\ a package-info.java file has already been seen for package {0} # 0: path -compiler.warn.lint.path.path.element.not.found=\ +# lint: path +compiler.warn.path.element.not.found=\ bad path element "{0}": no such file or directory -compiler.warn.lint.fallthrough.possible.fall-through.into.case=\ +# lint: fallthrough +compiler.warn.possible.fall-through.into.case=\ possible fall-through into case # 0: type -compiler.warn.lint.cast.redundant.cast=\ +# lint: cast +compiler.warn.redundant.cast=\ redundant cast to {0} # 0: number @@ -2117,19 +2150,23 @@ compiler.warn.invalid.utf8.in.classfile=\ {0}: classfile contains invalid UTF-8: {1} # 0: kind name, 1: symbol -compiler.warn.lint.static.static.not.qualified.by.type=\ +# lint: static +compiler.warn.static.not.qualified.by.type=\ static {0} should be qualified by type name, {1}, instead of by an expression # 0: kind name -compiler.warn.lint.static.static.not.qualified.by.type2=\ +# lint: static +compiler.warn.static.not.qualified.by.type2=\ static {0} should not be used as a member of an anonymous class # 0: string, 1: fragment -compiler.warn.lint.options.source.no.bootclasspath=\ +# lint: options +compiler.warn.source.no.bootclasspath=\ bootstrap class path is not set in conjunction with -source {0}\n{1} # 0: string, 1: fragment -compiler.warn.lint.options.source.no.system.modules.path=\ +# lint: options +compiler.warn.source.no.system.modules.path=\ location of system modules is not set in conjunction with -source {0}\n{1} # 0: string @@ -2153,11 +2190,13 @@ compiler.misc.source.no.system.modules.path.with.target=\ --release {0} is recommended instead of -source {0} -target {1} because it sets the location of system modules automatically # 0: string -compiler.warn.lint.options.option.obsolete.source=\ +# lint: options +compiler.warn.option.obsolete.source=\ source value {0} is obsolete and will be removed in a future release # 0: target -compiler.warn.lint.options.option.obsolete.target=\ +# lint: options +compiler.warn.option.obsolete.target=\ target value {0} is obsolete and will be removed in a future release # 0: string, 1: string @@ -2168,149 +2207,186 @@ compiler.err.option.removed.source=\ compiler.err.option.removed.target=\ Target option {0} is no longer supported. Use {1} or later. -compiler.warn.lint.options.option.obsolete.suppression=\ +# lint: options +compiler.warn.option.obsolete.suppression=\ To suppress warnings about obsolete options, use -Xlint:-options. # 0: name, 1: number, 2: number, 3: number, 4: number -compiler.warn.lint.classfile.future.attr=\ +# lint: classfile +compiler.warn.future.attr=\ {0} attribute introduced in version {1}.{2} class files is ignored in version {3}.{4} class files -compiler.warn.lint.requires-automatic.requires.automatic=\ +# lint: requires-automatic +compiler.warn.requires.automatic=\ requires directive for an automatic module -compiler.warn.lint.requires-transitive-automatic.requires.transitive.automatic=\ +# lint: requires-transitive-automatic +compiler.warn.requires.transitive.automatic=\ requires transitive directive for an automatic module # Warnings related to annotation processing # 0: string -compiler.warn.lint.processing.proc.package.does.not.exist=\ +# lint: processing +compiler.warn.proc.package.does.not.exist=\ package {0} does not exist # 0: string -compiler.warn.lint.processing.proc.file.reopening=\ +# lint: processing +compiler.warn.proc.file.reopening=\ Attempt to create a file for ''{0}'' multiple times # 0: string -compiler.warn.lint.processing.proc.type.already.exists=\ +# lint: processing +compiler.warn.proc.type.already.exists=\ A file for type ''{0}'' already exists on the sourcepath or classpath # 0: string -compiler.warn.lint.processing.proc.type.recreate=\ +# lint: processing +compiler.warn.proc.type.recreate=\ Attempt to create a file for type ''{0}'' multiple times # 0: string -compiler.warn.lint.processing.proc.illegal.file.name=\ +# lint: processing +compiler.warn.proc.illegal.file.name=\ Cannot create file for illegal name ''{0}''. # 0: string, 1: string -compiler.warn.lint.processing.proc.suspicious.class.name=\ +# lint: processing +compiler.warn.proc.suspicious.class.name=\ Creating file for a type whose name ends in {1}: ''{0}'' # 0: string -compiler.warn.lint.processing.proc.file.create.last.round=\ +# lint: processing +compiler.warn.proc.file.create.last.round=\ File for type ''{0}'' created in the last round will not be subject to annotation processing. # 0: string, 1: string -compiler.warn.lint.processing.proc.malformed.supported.string=\ +# lint: processing +compiler.warn.proc.malformed.supported.string=\ Malformed string ''{0}'' for a supported annotation interface returned by processor ''{1}'' # 0: set of string -compiler.warn.lint.processing.proc.annotations.without.processors=\ +# lint: processing +compiler.warn.proc.annotations.without.processors=\ No processor claimed any of these annotations: {0} # 0: source version, 1: string, 2: string -compiler.warn.lint.processing.proc.processor.incompatible.source.version=\ +# lint: processing +compiler.warn.proc.processor.incompatible.source.version=\ Supported source version ''{0}'' from annotation processor ''{1}'' less than -source ''{2}'' # 0: string, 1: string -compiler.warn.lint.processing.proc.duplicate.option.name=\ +# lint: processing +compiler.warn.proc.duplicate.option.name=\ Duplicate supported option ''{0}'' returned by annotation processor ''{1}'' # 0: string, 1: string -compiler.warn.lint.processing.proc.duplicate.supported.annotation=\ +# lint: processing +compiler.warn.proc.duplicate.supported.annotation=\ Duplicate supported annotation interface ''{0}'' returned by annotation processor ''{1}'' # 0: string -compiler.warn.lint.processing.proc.redundant.types.with.wildcard=\ +# lint: processing +compiler.warn.proc.redundant.types.with.wildcard=\ Annotation processor ''{0}'' redundantly supports both ''*'' and other annotation interfaces -compiler.warn.lint.processing.proc.proc-only.requested.no.procs=\ +# lint: processing +compiler.warn.proc.proc-only.requested.no.procs=\ Annotation processing without compilation requested but no processors were found. -compiler.warn.lint.processing.proc.use.implicit=\ +# lint: processing +compiler.warn.proc.use.implicit=\ Implicitly compiled files were not subject to annotation processing.\n\ Use -implicit to specify a policy for implicit compilation. -compiler.warn.lint.processing.proc.use.proc.or.implicit=\ +# lint: processing +compiler.warn.proc.use.proc.or.implicit=\ Implicitly compiled files were not subject to annotation processing.\n\ Use -proc:none to disable annotation processing or -implicit to specify a policy for implicit compilation. # Print a client-generated warning; assumed to be localized, no translation required # 0: string -compiler.warn.lint.processing.proc.messager=\ +# lint: processing +compiler.warn.proc.messager=\ {0} # 0: set of string -compiler.warn.lint.processing.proc.unclosed.type.files=\ +# lint: processing +compiler.warn.proc.unclosed.type.files=\ Unclosed files for the types ''{0}''; these types will not undergo annotation processing # 0: string -compiler.warn.lint.processing.proc.unmatched.processor.options=\ +# lint: processing +compiler.warn.proc.unmatched.processor.options=\ The following options were not recognized by any processor: ''{0}'' -compiler.warn.lint.try.try.explicit.close.call=\ +# lint: try +compiler.warn.try.explicit.close.call=\ explicit call to close() on an auto-closeable resource # 0: symbol -compiler.warn.lint.try.try.resource.not.referenced=\ +# lint: try +compiler.warn.try.resource.not.referenced=\ auto-closeable resource {0} is never referenced in body of corresponding try statement # 0: type -compiler.warn.lint.try.try.resource.throws.interrupted.exc=\ +# lint: try +compiler.warn.try.resource.throws.interrupted.exc=\ auto-closeable resource {0} has a member method close() that could throw InterruptedException -compiler.warn.lint.unchecked.unchecked.assign=\ +# lint: unchecked +compiler.warn.unchecked.assign=\ unchecked assignment: {0} to {1} # 0: symbol, 1: type -compiler.warn.lint.unchecked.unchecked.assign.to.var=\ +# lint: unchecked +compiler.warn.unchecked.assign.to.var=\ unchecked assignment to variable {0} as member of raw type {1} # 0: symbol, 1: type -compiler.warn.lint.unchecked.unchecked.call.mbr.of.raw.type=\ +# lint: unchecked +compiler.warn.unchecked.call.mbr.of.raw.type=\ unchecked call to {0} as a member of the raw type {1} -compiler.warn.lint.unchecked.unchecked.cast.to.type=\ +# lint: unchecked +compiler.warn.unchecked.cast.to.type=\ unchecked cast to type {0} # 0: kind name, 1: name, 2: object, 3: object, 4: kind name, 5: symbol -compiler.warn.lint.unchecked.unchecked.meth.invocation.applied=\ +# lint: unchecked +compiler.warn.unchecked.meth.invocation.applied=\ unchecked method invocation: {0} {1} in {4} {5} is applied to given types\n\ required: {2}\n\ found: {3} # 0: type -compiler.warn.lint.unchecked.unchecked.generic.array.creation=\ +# lint: unchecked +compiler.warn.unchecked.generic.array.creation=\ unchecked generic array creation for varargs parameter of type {0} # 0: type -compiler.warn.lint.unchecked.unchecked.varargs.non.reifiable.type=\ +# lint: unchecked +compiler.warn.unchecked.varargs.non.reifiable.type=\ Possible heap pollution from parameterized vararg type {0} # 0: symbol -compiler.warn.lint.varargs.varargs.unsafe.use.varargs.param=\ +# lint: varargs +compiler.warn.varargs.unsafe.use.varargs.param=\ Varargs method could cause heap pollution from non-reifiable varargs parameter {0} -compiler.warn.lint.dep-ann.missing.deprecated.annotation=\ +# lint: dep-ann +compiler.warn.missing.deprecated.annotation=\ deprecated item is not annotated with @Deprecated # 0: kind name -compiler.warn.lint.deprecation.deprecated.annotation.has.no.effect=\ +# lint: deprecation +compiler.warn.deprecated.annotation.has.no.effect=\ @Deprecated annotation has no effect on this {0} declaration # 0: string -compiler.warn.lint.path.invalid.path=\ +# lint: path +compiler.warn.invalid.path=\ Invalid filename: {0} compiler.warn.doclint.not.available=\ @@ -2322,21 +2398,25 @@ compiler.err.invalid.path=\ # 0: path -compiler.warn.lint.path.invalid.archive.file=\ +# lint: path +compiler.warn.invalid.archive.file=\ Unexpected file on path: {0} # 0: path -compiler.warn.lint.path.unexpected.archive.file=\ +# lint: path +compiler.warn.unexpected.archive.file=\ Unexpected extension for archive file: {0} # 0: path compiler.err.no.zipfs.for.archive=\ No file system provider is available to handle this file: {0} -compiler.warn.lint.divzero.div.zero=\ +# lint: divzero +compiler.warn.div.zero=\ division by zero -compiler.warn.lint.empty.empty.if=\ +# lint: empty +compiler.warn.empty.if=\ empty statement after if # 0: type, 1: name @@ -2362,7 +2442,8 @@ compiler.warn.unknown.enum.constant.reason=\ reason: {3} # 0: type, 1: type -compiler.warn.lint.rawtypes.raw.class.use=\ +# lint: rawtypes +compiler.warn.raw.class.use=\ found raw type: {0}\n\ missing type arguments for generic class {1} @@ -2379,7 +2460,8 @@ compiler.warn.method.redundant.typeargs=\ Redundant type arguments in method call. # 0: symbol, 1: message segment -compiler.warn.lint.varargs.varargs.redundant.trustme.anno=\ +# lint: varargs +compiler.warn.varargs.redundant.trustme.anno=\ Redundant {0} annotation. {1} # 0: symbol @@ -2544,13 +2626,15 @@ compiler.misc.bad.enclosing.method=\ bad enclosing method attribute for class {0} # 0: file name -compiler.warn.lint.classfile.runtime.visible.invisible.param.annotations.mismatch=\ +# lint: classfile +compiler.warn.runtime.visible.invisible.param.annotations.mismatch=\ the length of parameters in RuntimeVisibleParameterAnnotations attribute and \ RuntimeInvisibleParameterAnnotations attribute in: {0} \ do not match, ignoring both attributes # 0: file name -compiler.warn.lint.classfile.runtime.invisible.parameter.annotations=\ +# lint: classfile +compiler.warn.runtime.invisible.parameter.annotations=\ the RuntimeVisibleParameterAnnotations and RuntimeInvisibleParameterAnnotations attributes \ in: {0} \ cannot be mapped to the method''s parameters @@ -2690,7 +2774,8 @@ compiler.misc.possible.loss.of.precision=\ possible lossy conversion from {0} to {1} # 0: type, 1: type -compiler.warn.lint.lossy-conversions.possible.loss.of.precision=\ +# lint: lossy-conversions +compiler.warn.possible.loss.of.precision=\ implicit cast from {0} to {1} in compound assignment is possibly lossy compiler.misc.unchecked.assign=\ @@ -2865,7 +2950,8 @@ compiler.misc.varargs.argument.mismatch=\ ##### # 0: symbol or type, 1: file name -compiler.warn.lint.auxiliaryclass.auxiliary.class.accessed.from.outside.of.its.source.file=\ +# lint: auxiliaryclass +compiler.warn.auxiliary.class.accessed.from.outside.of.its.source.file=\ auxiliary class {0} in {1} should not be accessed from outside its own source file ## The first argument ({0}) is a "kindname". @@ -3079,7 +3165,8 @@ compiler.warn.override.unchecked.thrown=\ overridden method does not throw {1} # 0: symbol -compiler.warn.lint.overrides.override.equals.but.not.hashcode=\ +# lint: overrides +compiler.warn.override.equals.but.not.hashcode=\ Class {0} overrides equals, but neither it nor any superclass overrides hashCode method ## The following are all possible strings for the first argument ({0}) of the @@ -3171,15 +3258,18 @@ compiler.err.preview.feature.disabled.classfile=\ (use --enable-preview to allow loading of class files which contain preview features) # 0: message segment (feature) -compiler.warn.lint.preview.preview.feature.use=\ +# lint: preview +compiler.warn.preview.feature.use=\ {0} is a preview feature and may be removed in a future release. # 0: message segment (feature) -compiler.warn.lint.preview.preview.feature.use.plural=\ +# lint: preview +compiler.warn.preview.feature.use.plural=\ {0} are a preview feature and may be removed in a future release. # 0: file object (classfile), 1: string (expected version) -compiler.warn.lint.preview.preview.feature.use.classfile=\ +# lint: preview +compiler.warn.preview.feature.use.classfile=\ class file for {0} uses preview features of Java SE {1}. compiler.misc.feature.modules=\ @@ -3561,7 +3651,8 @@ compiler.err.module.not.found=\ module not found: {0} # 0: symbol -compiler.warn.lint.module.module.not.found=\ +# lint: module +compiler.warn.module.not.found=\ module not found: {0} # 0: name @@ -3656,7 +3747,8 @@ compiler.err.package.empty.or.not.found=\ package is empty or does not exist: {0} # 0: symbol -compiler.warn.lint.opens.package.empty.or.not.found=\ +# lint: opens +compiler.warn.package.empty.or.not.found=\ package is empty or does not exist: {0} compiler.err.no.output.dir=\ @@ -3739,7 +3831,8 @@ compiler.err.bad.name.for.option=\ bad name in value for {0} option: ''{1}'' # 0: option name, 1: symbol -compiler.warn.lint.options.module.for.option.not.found=\ +# lint: options +compiler.warn.module.for.option.not.found=\ module name in {0} option not found: {1} compiler.err.addmods.all.module.path.invalid=\ @@ -3754,7 +3847,8 @@ compiler.err.add.exports.with.release=\ compiler.err.add.reads.with.release=\ adding read edges for system module {0} is not allowed with --release -compiler.warn.lint.options.addopens.ignored=\ +# lint: options +compiler.warn.addopens.ignored=\ --add-opens has no effect at compile time compiler.misc.locn.module_source_path=\ @@ -3784,16 +3878,20 @@ compiler.warn.service.provided.but.not.exported.or.used=\ service interface provided but not exported or used # 0: kind name, 1: symbol, 2: symbol -compiler.warn.lint.exports.leaks.not.accessible=\ +# lint: exports +compiler.warn.leaks.not.accessible=\ {0} {1} in module {2} is not accessible to clients that require this module # 0: kind name, 1: symbol, 2: symbol -compiler.warn.lint.exports.leaks.not.accessible.unexported=\ +# lint: exports +compiler.warn.leaks.not.accessible.unexported=\ {0} {1} in module {2} is not exported # 0: kind name, 1: symbol, 2: symbol -compiler.warn.lint.exports.leaks.not.accessible.not.required.transitive=\ +# lint: exports +compiler.warn.leaks.not.accessible.not.required.transitive=\ {0} {1} in module {2} is not indirectly exported using ''requires transitive'' # 0: kind name, 1: symbol, 2: symbol -compiler.warn.lint.exports.leaks.not.accessible.unexported.qualified=\ +# lint: exports +compiler.warn.leaks.not.accessible.unexported.qualified=\ {0} {1} in module {2} may not be visible to all clients that require this module ### @@ -4125,7 +4223,8 @@ compiler.err.incorrect.number.of.nested.patterns=\ compiler.warn.declared.using.preview=\ {0} {1} is declared using a preview feature, which may be removed in a future release. -compiler.warn.lint.synchronization.attempt.to.synchronize.on.instance.of.value.based.class=\ +# lint: synchronization +compiler.warn.attempt.to.synchronize.on.instance.of.value.based.class=\ attempt to synchronize on an instance of a value-based class # 0: type diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_de.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_de.properties index 0192693dc1910..33063b6558d3a 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_de.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_de.properties @@ -1414,31 +1414,31 @@ compiler.warn.OSF.array.SPF=serialPersistentFields muss den Typ "java.io.ObjectS compiler.warn.missing.SVUID=Serialisierbare Klasse {0} enthält keine Definition von serialVersionUID # 0: name -compiler.warn.lint.serializable.missing.access.no.arg.ctor=Zugriff auf einen no-arg-Konstruktor in der ersten nicht serialisierbaren Superklasse {0} nicht möglich +compiler.warn.serializable.missing.access.no.arg.ctor=Zugriff auf einen no-arg-Konstruktor in der ersten nicht serialisierbaren Superklasse {0} nicht möglich # 0: name -compiler.warn.lint.serial.method.not.private=Serialisierungsbezogene Methode {0} nicht als privat deklariert +compiler.warn.serial.method.not.private=Serialisierungsbezogene Methode {0} nicht als privat deklariert # 0: name -compiler.warn.lint.serial.concrete.instance.method=Serialisierungsbezogene Methode {0} muss eine konkrete Instanzmethode sein, um in Kraft zu treten. Sie darf nicht abstrakt oder statisch sein +compiler.warn.serial.concrete.instance.method=Serialisierungsbezogene Methode {0} muss eine konkrete Instanzmethode sein, um in Kraft zu treten. Sie darf nicht abstrakt oder statisch sein # 0: name -compiler.warn.lint.serial.method.static=Serialisierungsbezogene Methode {0} ist als statisch deklariert. Sie muss stattdessen eine Instanzmethode sein, um in Kraft zu treten. +compiler.warn.serial.method.static=Serialisierungsbezogene Methode {0} ist als statisch deklariert. Sie muss stattdessen eine Instanzmethode sein, um in Kraft zu treten. # 0: name -compiler.warn.lint.serial.method.no.args=Serialisierungsbezogene Methode {0} darf keine Parameter aufweisen, um in Kraft zu treten +compiler.warn.serial.method.no.args=Serialisierungsbezogene Methode {0} darf keine Parameter aufweisen, um in Kraft zu treten # 0: name, 1: number -compiler.warn.lint.serial.method.one.arg=Serialisierungsbezogene Methode {0} muss genau einen Parameter aufweisen, um in Kraft zu treten. Sie darf nicht {1} Parameter enthalten +compiler.warn.serial.method.one.arg=Serialisierungsbezogene Methode {0} muss genau einen Parameter aufweisen, um in Kraft zu treten. Sie darf nicht {1} Parameter enthalten # 0: name, 1: type, 2: type -compiler.warn.lint.serial.method.parameter.type=Der einzige Parameter der serialisierungsbezogenen Methode {0} muss den Typ {1} haben, um in Kraft zu treten. Er darf nicht den Typ {2} aufweisen +compiler.warn.serial.method.parameter.type=Der einzige Parameter der serialisierungsbezogenen Methode {0} muss den Typ {1} haben, um in Kraft zu treten. Er darf nicht den Typ {2} aufweisen # 0: name, 1: type, 2: type -compiler.warn.lint.serial.method.unexpected.return.type=Serialisierungsbezogene Methode {0} wurde mit dem Rückgabetyp {1} und nicht dem erwarteten Typ {2} deklariert.\nMit dieser Deklaration ist die Methode ungültig für die Serialisierung +compiler.warn.serial.method.unexpected.return.type=Serialisierungsbezogene Methode {0} wurde mit dem Rückgabetyp {1} und nicht dem erwarteten Typ {2} deklariert.\nMit dieser Deklaration ist die Methode ungültig für die Serialisierung # 0: name, 1: type -compiler.warn.lint.serial.method.unexpected.exception=Serialisierungsbezogene Methode {0} wurde zum Auslösen eines unerwarteten Typs {1} deklariert +compiler.warn.serial.method.unexpected.exception=Serialisierungsbezogene Methode {0} wurde zum Auslösen eines unerwarteten Typs {1} deklariert compiler.warn.ineffectual.serial.field.interface=serialPersistentFields ist in einer Schnittstelle nicht effektiv diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_ja.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_ja.properties index 089f1b02211db..818b5fb70668b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_ja.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_ja.properties @@ -1414,31 +1414,31 @@ compiler.warn.OSF.array.SPF=serialPersistentFieldsを有効にするには、タ compiler.warn.missing.SVUID=直列化可能なクラス{0}には、serialVersionUIDが定義されていません # 0: name -compiler.warn.lint.serializable.missing.access.no.arg.ctor=シリアライズ不可のスーパークラス{0}で引数なしのコンストラクタにアクセスできません +compiler.warn.serializable.missing.access.no.arg.ctor=シリアライズ不可のスーパークラス{0}で引数なしのコンストラクタにアクセスできません # 0: name -compiler.warn.lint.serial.method.not.private=シリアライズ関連メソッド{0}はprivateとして宣言されていません +compiler.warn.serial.method.not.private=シリアライズ関連メソッド{0}はprivateとして宣言されていません # 0: name -compiler.warn.lint.serial.concrete.instance.method=シリアライズ関連メソッド{0}を有効にするには、concreteインスタンス・メソッドである必要があります。abstractでもstaticでもありません +compiler.warn.serial.concrete.instance.method=シリアライズ関連メソッド{0}を有効にするには、concreteインスタンス・メソッドである必要があります。abstractでもstaticでもありません # 0: name -compiler.warn.lint.serial.method.static=シリアライズ関連メソッド{0}がstaticとして宣言されています。有効にするには、かわりにインスタンス・メソッドにする必要があります +compiler.warn.serial.method.static=シリアライズ関連メソッド{0}がstaticとして宣言されています。有効にするには、かわりにインスタンス・メソッドにする必要があります # 0: name -compiler.warn.lint.serial.method.no.args=有効にするには、シリアライズ関連メソッド{0}にパラメータを指定しないでください +compiler.warn.serial.method.no.args=有効にするには、シリアライズ関連メソッド{0}にパラメータを指定しないでください # 0: name, 1: number -compiler.warn.lint.serial.method.one.arg=有効にするには、シリアライズ関連メソッド{0}に、{1}のパラメータではなく、パラメータを1つのみ指定する必要があります +compiler.warn.serial.method.one.arg=有効にするには、シリアライズ関連メソッド{0}に、{1}のパラメータではなく、パラメータを1つのみ指定する必要があります # 0: name, 1: type, 2: type -compiler.warn.lint.serial.method.parameter.type=有効にするには、シリアライズ関連メソッド{0}の1つのパラメータに、型{2}ではなく、型{1}を指定する必要があります +compiler.warn.serial.method.parameter.type=有効にするには、シリアライズ関連メソッド{0}の1つのパラメータに、型{2}ではなく、型{1}を指定する必要があります # 0: name, 1: type, 2: type -compiler.warn.lint.serial.method.unexpected.return.type=シリアライズ関連メソッド{0}は、必要な型{2}ではなく、{1}の戻り型で宣言されています。\n宣言されているように、メソッドはシリアライズが無効になります +compiler.warn.serial.method.unexpected.return.type=シリアライズ関連メソッド{0}は、必要な型{2}ではなく、{1}の戻り型で宣言されています。\n宣言されているように、メソッドはシリアライズが無効になります # 0: name, 1: type -compiler.warn.lint.serial.method.unexpected.exception=シリアライズ関連メソッド{0}は予期しない型{1}をスローするように宣言されています +compiler.warn.serial.method.unexpected.exception=シリアライズ関連メソッド{0}は予期しない型{1}をスローするように宣言されています compiler.warn.ineffectual.serial.field.interface=serialPersistentFieldsはインタフェースで有効ではありません diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_zh_CN.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_zh_CN.properties index 9f9b49159c54e..54298cb23b912 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_zh_CN.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler_zh_CN.properties @@ -1414,31 +1414,31 @@ compiler.warn.OSF.array.SPF=serialPersistentFields 的类型必须为 java.io.Ob compiler.warn.missing.SVUID=可序列化类{0}没有 serialVersionUID 的定义 # 0: name -compiler.warn.lint.serializable.missing.access.no.arg.ctor=无法访问第一个不可序列化超类 {0} 中的无参数构造器 +compiler.warn.serializable.missing.access.no.arg.ctor=无法访问第一个不可序列化超类 {0} 中的无参数构造器 # 0: name -compiler.warn.lint.serial.method.not.private=与序列化相关的方法 {0} 未声明为 private +compiler.warn.serial.method.not.private=与序列化相关的方法 {0} 未声明为 private # 0: name -compiler.warn.lint.serial.concrete.instance.method=与序列化相关的方法 {0} 必须是具体的实例方法才能生效,既不能是抽象方法也不能是静态方法 +compiler.warn.serial.concrete.instance.method=与序列化相关的方法 {0} 必须是具体的实例方法才能生效,既不能是抽象方法也不能是静态方法 # 0: name -compiler.warn.lint.serial.method.static=与序列化相关的方法 {0} 声明为 static;必须改为实例方法才能有效 +compiler.warn.serial.method.static=与序列化相关的方法 {0} 声明为 static;必须改为实例方法才能有效 # 0: name -compiler.warn.lint.serial.method.no.args=与序列化相关的方法 {0} 必须没有参数才能生效 +compiler.warn.serial.method.no.args=与序列化相关的方法 {0} 必须没有参数才能生效 # 0: name, 1: number -compiler.warn.lint.serial.method.one.arg=与序列化相关的方法 {0} 必须只有一个参数(而非 {1} 个参数)才能生效 +compiler.warn.serial.method.one.arg=与序列化相关的方法 {0} 必须只有一个参数(而非 {1} 个参数)才能生效 # 0: name, 1: type, 2: type -compiler.warn.lint.serial.method.parameter.type=与序列化相关的方法 {0} 的唯一参数的类型必须为 {1}(而非 {2})才能生效 +compiler.warn.serial.method.parameter.type=与序列化相关的方法 {0} 的唯一参数的类型必须为 {1}(而非 {2})才能生效 # 0: name, 1: type, 2: type -compiler.warn.lint.serial.method.unexpected.return.type=与序列化相关的方法 {0} 是用返回类型 {1}(而不是预期类型 {2})声明的。\n如声明的那样,该方法对序列化无效 +compiler.warn.serial.method.unexpected.return.type=与序列化相关的方法 {0} 是用返回类型 {1}(而不是预期类型 {2})声明的。\n如声明的那样,该方法对序列化无效 # 0: name, 1: type -compiler.warn.lint.serial.method.unexpected.exception=与序列化相关的方法 {0} 声明为抛出意外类型 {1} +compiler.warn.serial.method.unexpected.exception=与序列化相关的方法 {0} 声明为抛出意外类型 {1} compiler.warn.ineffectual.serial.field.interface=serialPersistentFields 在接口中无效 diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java index 0ee5f1138831f..40557afcce4f4 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java @@ -586,10 +586,7 @@ public static sealed class Warning extends DiagnosticInfo { final LintCategory category; public Warning(String prefix, String key, Object... args) { - super(DiagnosticType.WARNING, prefix, key, args); - category = key.contains(".lint.") ? - LintCategory.get(key.split("\\.")[2]) : - null; + this(null, prefix, key, args); } public Warning(LintCategory category, String prefix, String key, Object... args) { diff --git a/test/langtools/tools/javac/diags/examples/SerialMissingNoArgCtor.java b/test/langtools/tools/javac/diags/examples/SerialMissingNoArgCtor.java index 8d9b4964ee392..0bb028a69a66f 100644 --- a/test/langtools/tools/javac/diags/examples/SerialMissingNoArgCtor.java +++ b/test/langtools/tools/javac/diags/examples/SerialMissingNoArgCtor.java @@ -21,7 +21,7 @@ * questions. */ -// key: compiler.warn.lint.serializable.missing.access.no.arg.ctor +// key: compiler.warn.serializable.missing.access.no.arg.ctor // key: compiler.warn.non.serializable.instance.field // key: compiler.warn.non.serializable.instance.field.array diff --git a/test/langtools/tools/javac/diags/examples/SerialNonPrivateMethod.java b/test/langtools/tools/javac/diags/examples/SerialNonPrivateMethod.java index 0bdabb8bb0330..45f3273117b85 100644 --- a/test/langtools/tools/javac/diags/examples/SerialNonPrivateMethod.java +++ b/test/langtools/tools/javac/diags/examples/SerialNonPrivateMethod.java @@ -21,14 +21,14 @@ * questions. */ -// key: compiler.warn.lint.serial.method.not.private -// key: compiler.warn.lint.serial.method.static -// key: compiler.warn.lint.serial.method.unexpected.return.type -// key: compiler.warn.lint.serial.concrete.instance.method -// key: compiler.warn.lint.serial.method.one.arg -// key: compiler.warn.lint.serial.method.parameter.type -// key: compiler.warn.lint.serial.method.no.args -// key: compiler.warn.lint.serial.method.unexpected.exception +// key: compiler.warn.serial.method.not.private +// key: compiler.warn.serial.method.static +// key: compiler.warn.serial.method.unexpected.return.type +// key: compiler.warn.serial.concrete.instance.method +// key: compiler.warn.serial.method.one.arg +// key: compiler.warn.serial.method.parameter.type +// key: compiler.warn.serial.method.no.args +// key: compiler.warn.serial.method.unexpected.exception // options: -Xlint:serial diff --git a/test/langtools/tools/javac/warnings/Serial/CtorAccess.out b/test/langtools/tools/javac/warnings/Serial/CtorAccess.out index 380fdda80ba88..c271e8779f8b3 100644 --- a/test/langtools/tools/javac/warnings/Serial/CtorAccess.out +++ b/test/langtools/tools/javac/warnings/Serial/CtorAccess.out @@ -1,3 +1,3 @@ -CtorAccess.java:16:12: compiler.warn.lint.serializable.missing.access.no.arg.ctor: CtorAccess -CtorAccess.java:31:5: compiler.warn.lint.serializable.missing.access.no.arg.ctor: CtorAccess.MemberSuper +CtorAccess.java:16:12: compiler.warn.serializable.missing.access.no.arg.ctor: CtorAccess +CtorAccess.java:31:5: compiler.warn.serializable.missing.access.no.arg.ctor: CtorAccess.MemberSuper 2 warnings diff --git a/test/langtools/tools/javac/warnings/Serial/ImproperReturnTypes.out b/test/langtools/tools/javac/warnings/Serial/ImproperReturnTypes.out index 7891a6daa17c3..df5c0456d471a 100644 --- a/test/langtools/tools/javac/warnings/Serial/ImproperReturnTypes.out +++ b/test/langtools/tools/javac/warnings/Serial/ImproperReturnTypes.out @@ -1,6 +1,6 @@ -ImproperReturnTypes.java:24:17: compiler.warn.lint.serial.method.unexpected.return.type: writeObject, int, void -ImproperReturnTypes.java:29:17: compiler.warn.lint.serial.method.unexpected.return.type: writeReplace, int, java.lang.Object -ImproperReturnTypes.java:33:17: compiler.warn.lint.serial.method.unexpected.return.type: readObject, int, void -ImproperReturnTypes.java:39:17: compiler.warn.lint.serial.method.unexpected.return.type: readObjectNoData, int, void -ImproperReturnTypes.java:43:17: compiler.warn.lint.serial.method.unexpected.return.type: readResolve, int, java.lang.Object +ImproperReturnTypes.java:24:17: compiler.warn.serial.method.unexpected.return.type: writeObject, int, void +ImproperReturnTypes.java:29:17: compiler.warn.serial.method.unexpected.return.type: writeReplace, int, java.lang.Object +ImproperReturnTypes.java:33:17: compiler.warn.serial.method.unexpected.return.type: readObject, int, void +ImproperReturnTypes.java:39:17: compiler.warn.serial.method.unexpected.return.type: readObjectNoData, int, void +ImproperReturnTypes.java:43:17: compiler.warn.serial.method.unexpected.return.type: readResolve, int, java.lang.Object 5 warnings diff --git a/test/langtools/tools/javac/warnings/Serial/SerialMethodArity.out b/test/langtools/tools/javac/warnings/Serial/SerialMethodArity.out index 620e0511bfa3f..66f1c65305f0e 100644 --- a/test/langtools/tools/javac/warnings/Serial/SerialMethodArity.out +++ b/test/langtools/tools/javac/warnings/Serial/SerialMethodArity.out @@ -1,6 +1,6 @@ -SerialMethodArity.java:18:18: compiler.warn.lint.serial.method.parameter.type: writeObject, java.io.ObjectOutputStream, SerialMethodMods.CustomObjectOutputStream -SerialMethodArity.java:23:18: compiler.warn.lint.serial.method.one.arg: readObject, 2 -SerialMethodArity.java:29:39: compiler.warn.lint.serial.method.no.args: readObjectNoData -SerialMethodArity.java:32:36: compiler.warn.lint.serial.method.no.args: writeReplace -SerialMethodArity.java:37:38: compiler.warn.lint.serial.method.no.args: readResolve +SerialMethodArity.java:18:18: compiler.warn.serial.method.parameter.type: writeObject, java.io.ObjectOutputStream, SerialMethodMods.CustomObjectOutputStream +SerialMethodArity.java:23:18: compiler.warn.serial.method.one.arg: readObject, 2 +SerialMethodArity.java:29:39: compiler.warn.serial.method.no.args: readObjectNoData +SerialMethodArity.java:32:36: compiler.warn.serial.method.no.args: writeReplace +SerialMethodArity.java:37:38: compiler.warn.serial.method.no.args: readResolve 5 warnings diff --git a/test/langtools/tools/javac/warnings/Serial/SerialMethodMods.out b/test/langtools/tools/javac/warnings/Serial/SerialMethodMods.out index 83cfb680c9260..0f84b4cdf6e20 100644 --- a/test/langtools/tools/javac/warnings/Serial/SerialMethodMods.out +++ b/test/langtools/tools/javac/warnings/Serial/SerialMethodMods.out @@ -1,6 +1,6 @@ -SerialMethodMods.java:13:10: compiler.warn.lint.serial.method.not.private: writeObject -SerialMethodMods.java:18:17: compiler.warn.lint.serial.method.not.private: readObject -SerialMethodMods.java:24:25: compiler.warn.lint.serial.method.static: readObjectNoData -SerialMethodMods.java:27:28: compiler.warn.lint.serial.concrete.instance.method: writeReplace -SerialMethodMods.java:30:26: compiler.warn.lint.serial.concrete.instance.method: readResolve +SerialMethodMods.java:13:10: compiler.warn.serial.method.not.private: writeObject +SerialMethodMods.java:18:17: compiler.warn.serial.method.not.private: readObject +SerialMethodMods.java:24:25: compiler.warn.serial.method.static: readObjectNoData +SerialMethodMods.java:27:28: compiler.warn.serial.concrete.instance.method: writeReplace +SerialMethodMods.java:30:26: compiler.warn.serial.concrete.instance.method: readResolve 5 warnings diff --git a/test/langtools/tools/javac/warnings/Serial/SerialMethodThrows.out b/test/langtools/tools/javac/warnings/Serial/SerialMethodThrows.out index 0caedf0b9150a..fdb6765999bb3 100644 --- a/test/langtools/tools/javac/warnings/Serial/SerialMethodThrows.out +++ b/test/langtools/tools/javac/warnings/Serial/SerialMethodThrows.out @@ -1,6 +1,6 @@ -SerialMethodThrows.java:187:22: compiler.warn.lint.serial.method.unexpected.exception: writeObject, SerialMethodThrows.CustomException -SerialMethodThrows.java:196:24: compiler.warn.lint.serial.method.unexpected.exception: writeReplace, SerialMethodThrows.CustomException -SerialMethodThrows.java:201:22: compiler.warn.lint.serial.method.unexpected.exception: readObject, SerialMethodThrows.CustomException -SerialMethodThrows.java:210:22: compiler.warn.lint.serial.method.unexpected.exception: readObjectNoData, SerialMethodThrows.CustomException -SerialMethodThrows.java:213:24: compiler.warn.lint.serial.method.unexpected.exception: readResolve, SerialMethodThrows.CustomException +SerialMethodThrows.java:187:22: compiler.warn.serial.method.unexpected.exception: writeObject, SerialMethodThrows.CustomException +SerialMethodThrows.java:196:24: compiler.warn.serial.method.unexpected.exception: writeReplace, SerialMethodThrows.CustomException +SerialMethodThrows.java:201:22: compiler.warn.serial.method.unexpected.exception: readObject, SerialMethodThrows.CustomException +SerialMethodThrows.java:210:22: compiler.warn.serial.method.unexpected.exception: readObjectNoData, SerialMethodThrows.CustomException +SerialMethodThrows.java:213:24: compiler.warn.serial.method.unexpected.exception: readResolve, SerialMethodThrows.CustomException 5 warnings From c14773af6d826d19146e1d386ef9a6e941b0bb97 Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Mon, 2 Dec 2024 13:56:47 +0000 Subject: [PATCH 04/10] All tests pass --- .../tools/javac/resources/compiler.properties | 22 ++------------- .../sun/tools/javac/util/JCDiagnostic.java | 28 +++++-------------- 2 files changed, 9 insertions(+), 41 deletions(-) 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 ee1d197412651..1872f7d653dde 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 @@ -1898,7 +1898,7 @@ compiler.warn.dir.path.element.not.directory=\ # 0: symbol, 1: symbol, 2: symbol # lint: missing-explicit-ctor -compiler.warn.missing.explicit.ctor=\ +compiler.warn.missing-explicit-ctor=\ class {0} in exported package {1} declares no explicit constructors, thereby exposing a default constructor to clients of module {2} # lint: strictfp @@ -2226,98 +2226,79 @@ compiler.warn.requires.transitive.automatic=\ # Warnings related to annotation processing # 0: string -# lint: processing compiler.warn.proc.package.does.not.exist=\ package {0} does not exist # 0: string -# lint: processing compiler.warn.proc.file.reopening=\ Attempt to create a file for ''{0}'' multiple times # 0: string -# lint: processing compiler.warn.proc.type.already.exists=\ A file for type ''{0}'' already exists on the sourcepath or classpath # 0: string -# lint: processing compiler.warn.proc.type.recreate=\ Attempt to create a file for type ''{0}'' multiple times # 0: string -# lint: processing compiler.warn.proc.illegal.file.name=\ Cannot create file for illegal name ''{0}''. # 0: string, 1: string -# lint: processing compiler.warn.proc.suspicious.class.name=\ Creating file for a type whose name ends in {1}: ''{0}'' # 0: string -# lint: processing compiler.warn.proc.file.create.last.round=\ File for type ''{0}'' created in the last round will not be subject to annotation processing. # 0: string, 1: string -# lint: processing compiler.warn.proc.malformed.supported.string=\ Malformed string ''{0}'' for a supported annotation interface returned by processor ''{1}'' # 0: set of string -# lint: processing compiler.warn.proc.annotations.without.processors=\ No processor claimed any of these annotations: {0} # 0: source version, 1: string, 2: string -# lint: processing compiler.warn.proc.processor.incompatible.source.version=\ Supported source version ''{0}'' from annotation processor ''{1}'' less than -source ''{2}'' # 0: string, 1: string -# lint: processing compiler.warn.proc.duplicate.option.name=\ Duplicate supported option ''{0}'' returned by annotation processor ''{1}'' # 0: string, 1: string -# lint: processing compiler.warn.proc.duplicate.supported.annotation=\ Duplicate supported annotation interface ''{0}'' returned by annotation processor ''{1}'' # 0: string -# lint: processing compiler.warn.proc.redundant.types.with.wildcard=\ Annotation processor ''{0}'' redundantly supports both ''*'' and other annotation interfaces -# lint: processing compiler.warn.proc.proc-only.requested.no.procs=\ Annotation processing without compilation requested but no processors were found. -# lint: processing compiler.warn.proc.use.implicit=\ Implicitly compiled files were not subject to annotation processing.\n\ Use -implicit to specify a policy for implicit compilation. -# lint: processing compiler.warn.proc.use.proc.or.implicit=\ Implicitly compiled files were not subject to annotation processing.\n\ Use -proc:none to disable annotation processing or -implicit to specify a policy for implicit compilation. # Print a client-generated warning; assumed to be localized, no translation required # 0: string -# lint: processing compiler.warn.proc.messager=\ {0} # 0: set of string -# lint: processing compiler.warn.proc.unclosed.type.files=\ Unclosed files for the types ''{0}''; these types will not undergo annotation processing # 0: string -# lint: processing compiler.warn.proc.unmatched.processor.options=\ The following options were not recognized by any processor: ''{0}'' @@ -2760,6 +2741,7 @@ compiler.misc.prob.found.req=\ incompatible types: {0} # 0: message segment, 1: type, 2: type +# lint: unchecked compiler.warn.prob.found.req=\ {0}\n\ required: {2}\n\ diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java index 40557afcce4f4..a8de786e1afbc 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java @@ -304,7 +304,9 @@ public JCDiagnostic create( //where DiagnosticInfo normalize(DiagnosticInfo diagnosticInfo) { //replace all nested FragmentKey with full-blown JCDiagnostic objects - return DiagnosticInfo.of(diagnosticInfo.type, diagnosticInfo.prefix, diagnosticInfo.code, + LintCategory category = diagnosticInfo instanceof Warning warning ? + warning.category : null; + return DiagnosticInfo.of(diagnosticInfo.type, category, diagnosticInfo.prefix, diagnosticInfo.code, Stream.of(diagnosticInfo.args).map(o -> { return (o instanceof Fragment frag) ? fragment(frag) : o; @@ -582,7 +584,7 @@ public Error(String prefix, String key, Object... args) { /** * Class representing warning diagnostic keys. */ - public static sealed class Warning extends DiagnosticInfo { + public static final class Warning extends DiagnosticInfo { final LintCategory category; public Warning(String prefix, String key, Object... args) { @@ -595,22 +597,6 @@ public Warning(LintCategory category, String prefix, String key, Object... args) } } - /** - * Class representing lint warning diagnostic keys. - */ - public static final class LintWarning extends Warning { - final LintCategory category; - - public LintWarning(String prefix, LintCategory lintCategory, String key, Object... args) { - super(prefix, key, args); - category = lintCategory; - } - - public LintWarning(String prefix, String key, Object... args) { - this(prefix, LintCategory.get(key.split("\\.")[2]), key, args); - } - } - /** * Class representing note diagnostic keys. */ @@ -704,15 +690,15 @@ public boolean isMandatory() { * Check whether this diagnostic has an associated lint category. */ public boolean hasLintCategory() { - return diagnosticInfo instanceof LintWarning; + return getLintCategory() != null; } /** * Get the associated lint category, or null if none. */ public LintCategory getLintCategory() { - return diagnosticInfo instanceof LintWarning lintWarning ? - lintWarning.category : null; + return diagnosticInfo instanceof Warning warning ? + warning.category : null; } /** From ebc51108bf3d37c7941a7bcee34a288fd5098e98 Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Mon, 2 Dec 2024 15:10:22 +0000 Subject: [PATCH 05/10] All langtools tests pass Readded Lint kind to processing warnings --- .../com/sun/tools/javac/code/Preview.java | 2 +- .../com/sun/tools/javac/comp/Attr.java | 6 +- .../com/sun/tools/javac/comp/Check.java | 162 +++++++++--------- .../com/sun/tools/javac/comp/Flow.java | 11 +- .../com/sun/tools/javac/comp/Modules.java | 7 +- .../tools/javac/comp/ThisEscapeAnalyzer.java | 5 +- .../sun/tools/javac/file/BaseFileManager.java | 7 +- .../com/sun/tools/javac/file/Locations.java | 22 ++- .../com/sun/tools/javac/jvm/ClassReader.java | 6 +- .../com/sun/tools/javac/main/Arguments.java | 14 +- .../sun/tools/javac/parser/JavaTokenizer.java | 4 +- .../sun/tools/javac/parser/JavacParser.java | 2 +- .../tools/javac/resources/compiler.properties | 12 ++ .../com/sun/tools/javac/util/AbstractLog.java | 37 +--- .../javac/util/MandatoryWarningHandler.java | 4 +- 15 files changed, 133 insertions(+), 168 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java index c66e17586161e..29b290b285e0a 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java @@ -188,7 +188,7 @@ public void warnPreview(DiagnosticPosition pos, Feature feature) { public void warnPreview(JavaFileObject classfile, int majorVersion) { Assert.check(isEnabled()); if (lint.isEnabled(LintCategory.PREVIEW)) { - log.mandatoryWarning(LintCategory.PREVIEW, null, + log.mandatoryWarning(null, Warnings.PreviewFeatureUseClassfile(classfile, majorVersionToSource.get(majorVersion).name)); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index 62f7c15a95f85..a18f82613e0f8 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -1939,7 +1939,7 @@ private Symbol enumConstant(JCTree tree, Type enumType) { public void visitSynchronized(JCSynchronized tree) { chk.checkRefType(tree.pos(), attribExpr(tree.lock, env)); if (env.info.lint.isEnabled(LintCategory.SYNCHRONIZATION) && isValueBased(tree.lock.type)) { - log.warning(LintCategory.SYNCHRONIZATION, tree.pos(), Warnings.AttemptToSynchronizeOnInstanceOfValueBasedClass); + log.warning(tree.pos(), Warnings.AttemptToSynchronizeOnInstanceOfValueBasedClass); } attribStat(tree.body, env); result = null; @@ -2047,7 +2047,7 @@ void checkAutoCloseable(DiagnosticPosition pos, Env env, Type resou close.overrides(syms.autoCloseableClose, resource.tsym, types, true) && chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes()) && env.info.lint.isEnabled(LintCategory.TRY)) { - log.warning(LintCategory.TRY, pos, Warnings.TryResourceThrowsInterruptedExc(resource)); + log.warning(pos, Warnings.TryResourceThrowsInterruptedExc(resource)); } } } @@ -4443,7 +4443,7 @@ public void visitSelect(JCFieldAccess tree) { sym.name.equals(names.close) && sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) && env.info.lint.isEnabled(LintCategory.TRY)) { - log.warning(LintCategory.TRY, tree, Warnings.TryExplicitCloseCall); + log.warning(tree, Warnings.TryExplicitCloseCall); } // Disallow selecting a type from an expression diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index 08084b5abed84..f425b818734ff 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -28,7 +28,6 @@ import java.util.*; import java.util.function.BiConsumer; import java.util.function.BiPredicate; -import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.function.ToIntBiFunction; @@ -79,11 +78,8 @@ import static com.sun.tools.javac.tree.JCTree.Tag.*; import javax.lang.model.element.Element; -import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.ElementFilter; import javax.lang.model.util.ElementKindVisitor14; /** Type checking helper class for the attribution phase. @@ -289,7 +285,7 @@ public void warnDeclaredUsingPreview(DiagnosticPosition pos, Symbol sym) { */ public void warnRestrictedAPI(DiagnosticPosition pos, Symbol sym) { if (lint.isEnabled(LintCategory.RESTRICTED)) - log.warning(LintCategory.RESTRICTED, pos, Warnings.RestrictedMethod(sym.enclClass(), sym)); + log.warning(pos, Warnings.RestrictedMethod(sym.enclClass(), sym)); } /** Warn about unchecked operation. @@ -306,12 +302,12 @@ public void warnUnchecked(DiagnosticPosition pos, Warning warnKey) { */ void warnUnsafeVararg(DiagnosticPosition pos, Warning warnKey) { if (lint.isEnabled(LintCategory.VARARGS)) - log.warning(LintCategory.VARARGS, pos, warnKey); + log.warning(pos, warnKey); } public void warnStatic(DiagnosticPosition pos, Warning warnKey) { if (lint.isEnabled(LintCategory.STATIC)) - log.warning(LintCategory.STATIC, pos, warnKey); + log.warning(pos, warnKey); } /** Warn about division by integer constant zero. @@ -319,7 +315,7 @@ public void warnStatic(DiagnosticPosition pos, Warning warnKey) { */ void warnDivZero(DiagnosticPosition pos) { if (lint.isEnabled(LintCategory.DIVZERO)) - log.warning(LintCategory.DIVZERO, pos, Warnings.DivZero); + log.warning(pos, Warnings.DivZero); } /** @@ -675,7 +671,7 @@ public void checkRedundantCast(Env env, final JCTypeCast tree) { && !is292targetTypeCast(tree)) { deferredLintHandler.report(_l -> { if (lint.isEnabled(LintCategory.CAST)) - log.warning(LintCategory.CAST, + log.warning( tree.pos(), Warnings.RedundantCast(tree.clazz.type)); }); } @@ -1352,8 +1348,8 @@ private void warnOnExplicitStrictfp(DiagnosticPosition pos) { try { deferredLintHandler.report(_l -> { if (lint.isEnabled(LintCategory.STRICTFP)) { - log.warning(LintCategory.STRICTFP, - pos, Warnings.Strictfp); } + log.warning( + pos, Warnings.Strictfp); } }); } finally { deferredLintHandler.setPos(prevLintPos); @@ -1574,7 +1570,7 @@ void checkRaw(JCTree tree, Env env) { !TreeInfo.isDiamond(tree) && !withinAnonConstr(env) && tree.type.isRaw()) { - log.warning(LintCategory.RAW, + log.warning( tree.pos(), Warnings.RawClassUse(tree.type, tree.type.tsym.type)); } } @@ -2247,7 +2243,7 @@ private void checkClassOverrideEqualsAndHash(DiagnosticPosition pos, someClass, false, equalsHasCodeFilter) != hashCodeAtObject; if (overridesEquals && !overridesHashCode) { - log.warning(LintCategory.OVERRIDES, pos, + log.warning(pos, Warnings.OverrideEqualsButNotHashcode(someClass)); } } @@ -2310,7 +2306,7 @@ public void checkModuleName (JCModuleDecl tree) { String moduleNameComponentString = componentName.toString(); int nameLength = moduleNameComponentString.length(); if (nameLength > 0 && Character.isDigit(moduleNameComponentString.charAt(nameLength - 1))) { - log.warning(Lint.LintCategory.MODULE, pos, Warnings.PoorChoiceForModuleName(componentName)); + log.warning(pos, Warnings.PoorChoiceForModuleName(componentName)); } } } @@ -2781,7 +2777,7 @@ void checkPotentiallyAmbiguousOverloads(JCClassDecl tree, Type site) { tree.pos(); // Log the warning - log.warning(LintCategory.OVERLOADS, pos, + log.warning(pos, Warnings.PotentiallyAmbiguousOverload( m1.asMemberOf(site, types), m1.location(), m2.asMemberOf(site, types), m2.location())); @@ -3002,7 +2998,7 @@ void checkAccessFromSerializableElement(final JCTree tree, boolean isLambda) { isEffectivelyNonPublic(sym)) { if (isLambda) { if (belongsToRestrictedPackage(sym)) { - log.warning(LintCategory.SERIAL, tree.pos(), + log.warning(tree.pos(), Warnings.AccessToMemberFromSerializableLambda(sym)); } } else { @@ -3790,13 +3786,13 @@ void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) { (s.flags() & DEPRECATED) != 0 && !syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) == null) { - log.warning(LintCategory.DEP_ANN, + log.warning( pos, Warnings.MissingDeprecatedAnnotation); } // Note: @Deprecated has no effect on local variables, parameters and package decls. if (lint.isEnabled(LintCategory.DEPRECATION) && !s.isDeprecatableViaAnnotation()) { if (!syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) != null) { - log.warning(LintCategory.DEPRECATION, pos, + log.warning(pos, Warnings.DeprecatedAnnotationHasNoEffect(Kinds.kindName(s))); } } @@ -4140,7 +4136,7 @@ void checkLossOfPrecision(final DiagnosticPosition pos, Type found, Type req) { if (found.isNumeric() && req.isNumeric() && !types.isAssignable(found, req)) { deferredLintHandler.report(_l -> { if (lint.isEnabled(LintCategory.LOSSY_CONVERSIONS)) - log.warning(LintCategory.LOSSY_CONVERSIONS, + log.warning( pos, Warnings.PossibleLossOfPrecision(found, req)); }); } @@ -4152,7 +4148,7 @@ void checkLossOfPrecision(final DiagnosticPosition pos, Type found, Type req) { void checkEmptyIf(JCIf tree) { if (tree.thenpart.hasTag(SKIP) && tree.elsepart == null && lint.isEnabled(LintCategory.EMPTY)) - log.warning(LintCategory.EMPTY, tree.thenpart.pos(), Warnings.EmptyIf); + log.warning(tree.thenpart.pos(), Warnings.EmptyIf); } /** Check that symbol is unique in given scope. @@ -4344,8 +4340,8 @@ void checkDefaultConstructor(ClassSymbol c, DiagnosticPosition pos) { // enabled in the deferred context. deferredLintHandler.report(_l -> { if (lint.isEnabled(LintCategory.MISSING_EXPLICIT_CTOR)) - log.warning(LintCategory.MISSING_EXPLICIT_CTOR, - pos, Warnings.MissingExplicitCtor(c, pkg, modle)); + log.warning( + pos, Warnings.MissingExplicitCtor(c, pkg, modle)); }); } else { return; @@ -4637,7 +4633,7 @@ private boolean isAPISymbol(Symbol sym) { } private void checkVisible(DiagnosticPosition pos, Symbol what, PackageSymbol inPackage, boolean inSuperType) { if (!isAPISymbol(what) && !inSuperType) { //package private/private element - log.warning(LintCategory.EXPORTS, pos, Warnings.LeaksNotAccessible(kindName(what), what, what.packge().modle)); + log.warning(pos, Warnings.LeaksNotAccessible(kindName(what), what, what.packge().modle)); return ; } @@ -4646,13 +4642,13 @@ private void checkVisible(DiagnosticPosition pos, Symbol what, PackageSymbol inP ExportsDirective inExport = findExport(inPackage); if (whatExport == null) { //package not exported: - log.warning(LintCategory.EXPORTS, pos, Warnings.LeaksNotAccessibleUnexported(kindName(what), what, what.packge().modle)); + log.warning(pos, Warnings.LeaksNotAccessibleUnexported(kindName(what), what, what.packge().modle)); return ; } if (whatExport.modules != null) { if (inExport.modules == null || !whatExport.modules.containsAll(inExport.modules)) { - log.warning(LintCategory.EXPORTS, pos, Warnings.LeaksNotAccessibleUnexportedQualified(kindName(what), what, what.packge().modle)); + log.warning(pos, Warnings.LeaksNotAccessibleUnexportedQualified(kindName(what), what, what.packge().modle)); } } @@ -4674,7 +4670,7 @@ private void checkVisible(DiagnosticPosition pos, Symbol what, PackageSymbol inP } } - log.warning(LintCategory.EXPORTS, pos, Warnings.LeaksNotAccessibleNotRequiredTransitive(kindName(what), what, what.packge().modle)); + log.warning(pos, Warnings.LeaksNotAccessibleNotRequiredTransitive(kindName(what), what, what.packge().modle)); } } @@ -4682,7 +4678,7 @@ void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) { if (msym.kind != MDL) { deferredLintHandler.report(_l -> { if (lint.isEnabled(LintCategory.MODULE)) - log.warning(LintCategory.MODULE, pos, Warnings.ModuleNotFound(msym)); + log.warning(pos, Warnings.ModuleNotFound(msym)); }); } } @@ -5001,7 +4997,7 @@ public Void visitTypeAsClass(TypeElement e, } if (svuidSym == null) { - log.warning(LintCategory.SERIAL, p.pos(), Warnings.MissingSVUID(c)); + log.warning(p.pos(), Warnings.MissingSVUID(c)); } // Check for serialPersistentFields to gate checks for @@ -5028,8 +5024,8 @@ public Void visitTypeAsClass(TypeElement e, // Note per JLS arrays are // serializable even if the // component type is not. - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(enclosed, tree), + log.warning( + TreeInfo.diagnosticPositionFor(enclosed, tree), Warnings.NonSerializableInstanceField); } else if (varType.hasTag(ARRAY)) { ArrayType arrayType = (ArrayType)varType; @@ -5039,8 +5035,8 @@ public Void visitTypeAsClass(TypeElement e, elementType = arrayType.elemtype; } if (!canBeSerialized(elementType)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(enclosed, tree), + log.warning( + TreeInfo.diagnosticPositionFor(enclosed, tree), Warnings.NonSerializableInstanceFieldArray(elementType)); } } @@ -5124,7 +5120,7 @@ private void checkCtorAccess(JCClassDecl tree, ClassSymbol c) { } } } - log.warning(LintCategory.SERIAL, tree.pos(), + log.warning(tree.pos(), Warnings.ExternalizableMissingPublicNoArgCtor); } else { // Approximate access to the no-arg constructor up in @@ -5152,7 +5148,7 @@ private void checkCtorAccess(JCClassDecl tree, ClassSymbol c) { // Handle nested classes and implicit this$0 (supertype.getNestingKind() == NestingKind.MEMBER && ((supertype.flags() & STATIC) == 0))) - log.warning(LintCategory.SERIAL, tree.pos(), + log.warning(tree.pos(), Warnings.SerializableMissingAccessNoArgCtor(supertype.getQualifiedName())); } } @@ -5171,21 +5167,21 @@ private void checkSerialVersionUID(JCClassDecl tree, Element e, VarSymbol svuid) // fields. if ((svuid.flags() & (STATIC | FINAL)) != (STATIC | FINAL)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(svuid, tree), + log.warning( + TreeInfo.diagnosticPositionFor(svuid, tree), Warnings.ImproperSVUID((Symbol)e)); } // check svuid has type long if (!svuid.type.hasTag(LONG)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(svuid, tree), + log.warning( + TreeInfo.diagnosticPositionFor(svuid, tree), Warnings.LongSVUID((Symbol)e)); } if (svuid.getConstValue() == null) - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(svuid, tree), + log.warning( + TreeInfo.diagnosticPositionFor(svuid, tree), Warnings.ConstantSVUID((Symbol)e)); } @@ -5193,20 +5189,20 @@ private void checkSerialPersistentFields(JCClassDecl tree, Element e, VarSymbol // To be effective, serialPersisentFields must be private, static, and final. if ((spf.flags() & (PRIVATE | STATIC | FINAL)) != (PRIVATE | STATIC | FINAL)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(spf, tree), + log.warning( + TreeInfo.diagnosticPositionFor(spf, tree), Warnings.ImproperSPF); } if (!types.isSameType(spf.type, OSF_TYPE)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(spf, tree), + log.warning( + TreeInfo.diagnosticPositionFor(spf, tree), Warnings.OSFArraySPF); } if (isExternalizable((Type)(e.asType()))) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(spf, tree), + log.warning( + TreeInfo.diagnosticPositionFor(spf, tree), Warnings.IneffectualSerialFieldExternalizable); } @@ -5217,7 +5213,7 @@ private void checkSerialPersistentFields(JCClassDecl tree, Element e, VarSymbol JCVariableDecl variableDef = (JCVariableDecl) spfDecl; JCExpression initExpr = variableDef.init; if (initExpr != null && TreeInfo.isNull(initExpr)) { - log.warning(LintCategory.SERIAL, initExpr.pos(), + log.warning(initExpr.pos(), Warnings.SPFNullInit); } } @@ -5296,8 +5292,8 @@ private void checkReadExternalRecord(JCClassDecl tree, Element e, MethodSymbol m private void checkExternMethodRecord(JCClassDecl tree, Element e, MethodSymbol method, Type argType, boolean isExtern) { if (isExtern && isExternMethod(tree, e, method, argType)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.IneffectualExternalizableMethodRecord(method.getSimpleName().toString())); } } @@ -5305,14 +5301,14 @@ private void checkExternMethodRecord(JCClassDecl tree, Element e, MethodSymbol m void checkPrivateNonStaticMethod(JCClassDecl tree, MethodSymbol method) { var flags = method.flags(); if ((flags & PRIVATE) == 0) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.SerialMethodNotPrivate(method.getSimpleName())); } if ((flags & STATIC) != 0) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.SerialMethodStatic(method.getSimpleName())); } } @@ -5336,8 +5332,8 @@ public Void visitTypeAsEnum(TypeElement e, case FIELD -> { var field = (VarSymbol)enclosed; if (serialFieldNames.contains(name)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(field, tree), + log.warning( + TreeInfo.diagnosticPositionFor(field, tree), Warnings.IneffectualSerialFieldEnum(name)); } } @@ -5345,8 +5341,8 @@ public Void visitTypeAsEnum(TypeElement e, case METHOD -> { var method = (MethodSymbol)enclosed; if (serialMethodNames.contains(name)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.IneffectualSerialMethodEnum(name)); } @@ -5385,8 +5381,8 @@ private void checkReadExternalEnum(JCClassDecl tree, Element e, MethodSymbol met private void checkExternMethodEnum(JCClassDecl tree, Element e, MethodSymbol method, Type argType) { if (isExternMethod(tree, e, method, argType)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.IneffectualExternMethodEnum(method.getSimpleName().toString())); } } @@ -5417,8 +5413,8 @@ public Void visitTypeAsInterface(TypeElement e, name = field.getSimpleName().toString(); switch(name) { case "serialPersistentFields" -> { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(field, tree), + log.warning( + TreeInfo.diagnosticPositionFor(field, tree), Warnings.IneffectualSerialFieldInterface); } @@ -5457,8 +5453,8 @@ private void checkPrivateMethod(JCClassDecl tree, Element e, MethodSymbol method) { if ((method.flags() & PRIVATE) == 0) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.NonPrivateMethodWeakerAccess); } } @@ -5467,8 +5463,8 @@ private void checkDefaultIneffective(JCClassDecl tree, Element e, MethodSymbol method) { if ((method.flags() & DEFAULT) == DEFAULT) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.DefaultIneffective); } @@ -5514,8 +5510,8 @@ public Void visitTypeAsRecord(TypeElement e, var field = (VarSymbol)enclosed; switch(name) { case "serialPersistentFields" -> { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(field, tree), + log.warning( + TreeInfo.diagnosticPositionFor(field, tree), Warnings.IneffectualSerialFieldRecord); } @@ -5538,8 +5534,8 @@ public Void visitTypeAsRecord(TypeElement e, default -> { if (serialMethodNames.contains(name)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.IneffectualSerialMethodRecord(name)); } }} @@ -5552,8 +5548,8 @@ void checkConcreteInstanceMethod(JCClassDecl tree, Element enclosing, MethodSymbol method) { if ((method.flags() & (STATIC | ABSTRACT)) != 0) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.SerialConcreteInstanceMethod(method.getSimpleName())); } } @@ -5569,8 +5565,8 @@ private void checkReturnType(JCClassDecl tree, // checking. Type rtype = method.getReturnType(); if (!types.isSameType(expectedReturnType, rtype)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.SerialMethodUnexpectedReturnType(method.getSimpleName(), rtype, expectedReturnType)); } @@ -5585,16 +5581,16 @@ private void checkOneArg(JCClassDecl tree, var parameters= method.getParameters(); if (parameters.size() != 1) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.SerialMethodOneArg(method.getSimpleName(), parameters.size())); return; } Type parameterType = parameters.get(0).asType(); if (!types.isSameType(parameterType, expectedType)) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.SerialMethodParameterType(method.getSimpleName(), expectedType, parameterType)); @@ -5614,8 +5610,8 @@ private boolean hasExactlyOneArgWithType(JCClassDecl tree, private void checkNoArgs(JCClassDecl tree, Element enclosing, MethodSymbol method) { var parameters = method.getParameters(); if (!parameters.isEmpty()) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(parameters.get(0), tree), + log.warning( + TreeInfo.diagnosticPositionFor(parameters.get(0), tree), Warnings.SerialMethodNoArgs(method.getSimpleName())); } } @@ -5623,8 +5619,8 @@ private void checkNoArgs(JCClassDecl tree, Element enclosing, MethodSymbol metho private void checkExternalizable(JCClassDecl tree, Element enclosing, MethodSymbol method) { // If the enclosing class is externalizable, warn for the method if (isExternalizable((Type)enclosing.asType())) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.IneffectualSerialMethodExternalizable(method.getSimpleName())); } return; @@ -5652,8 +5648,8 @@ private void checkExceptions(JCClassDecl tree, } } if (!declared) { - log.warning(LintCategory.SERIAL, - TreeInfo.diagnosticPositionFor(method, tree), + log.warning( + TreeInfo.diagnosticPositionFor(method, tree), Warnings.SerialMethodUnexpectedException(method.getSimpleName(), thrownType)); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java index df28548152aec..8a90dc88fa90d 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java @@ -34,7 +34,6 @@ import java.util.Set; import java.util.function.Consumer; -import com.sun.source.tree.CaseTree; import com.sun.source.tree.LambdaExpressionTree.BodyKind; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Scope.WriteableScope; @@ -60,8 +59,6 @@ import static com.sun.tools.javac.tree.JCTree.Tag.*; import com.sun.tools.javac.util.JCDiagnostic.Fragment; import java.util.Arrays; -import java.util.Collections; -import java.util.IdentityHashMap; import java.util.Iterator; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -728,8 +725,8 @@ public void visitSwitch(JCSwitch tree) { if (alive == Liveness.ALIVE && lint.isEnabled(Lint.LintCategory.FALLTHROUGH) && c.stats.nonEmpty() && l.tail.nonEmpty()) - log.warning(Lint.LintCategory.FALLTHROUGH, - l.tail.head.pos(), + log.warning( + l.tail.head.pos(), Warnings.PossibleFallThroughIntoCase); } tree.isExhaustive = tree.hasUnconditionalPattern || @@ -1238,7 +1235,7 @@ public void visitTry(JCTry tree) { tree.finallyCanCompleteNormally = alive != Liveness.DEAD; if (alive == Liveness.DEAD) { if (lint.isEnabled(Lint.LintCategory.FINALLY)) { - log.warning(Lint.LintCategory.FINALLY, + log.warning( TreeInfo.diagEndPos(tree.finalizer), Warnings.FinallyCannotComplete); } @@ -2863,7 +2860,7 @@ public void visitTry(JCTry tree) { lint.isEnabled(Lint.LintCategory.TRY)) { for (JCVariableDecl resVar : resourceVarDecls) { if (unrefdResources.includes(resVar.sym) && !resVar.sym.isUnnamedVariable()) { - log.warning(Lint.LintCategory.TRY, resVar.pos(), + log.warning(resVar.pos(), Warnings.TryResourceNotReferenced(resVar.sym)); unrefdResources.remove(resVar.sym); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java index bfad334d1942f..d0ed3abcaaf5b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java @@ -52,7 +52,6 @@ import javax.tools.StandardLocation; import com.sun.source.tree.ModuleTree.ModuleKind; -import com.sun.tools.javac.code.ClassFinder; import com.sun.tools.javac.code.DeferredLintHandler; import com.sun.tools.javac.code.Directive; import com.sun.tools.javac.code.Directive.ExportsDirective; @@ -1275,7 +1274,7 @@ private void setupAllModules() { if (lintOptions) { for (ModuleSymbol msym : limitMods) { if (!observable.contains(msym)) { - log.warning(LintCategory.OPTIONS, + log.warning( Warnings.ModuleForOptionNotFound(Option.LIMIT_MODULES, msym)); } } @@ -1731,7 +1730,7 @@ private boolean isKnownModule(ModuleSymbol msym, Set unknownModule if (!unknownModules.contains(msym)) { if (lintOptions) { - log.warning(LintCategory.OPTIONS, + log.warning( Warnings.ModuleForOptionNotFound(Option.ADD_EXPORTS, msym)); } unknownModules.add(msym); @@ -1790,7 +1789,7 @@ private void initAddReads() { targetModule = syms.enterModule(names.fromString(targetName)); if (!allModules.contains(targetModule)) { if (lintOptions) { - log.warning(LintCategory.OPTIONS, Warnings.ModuleForOptionNotFound(Option.ADD_READS, targetModule)); + log.warning(Warnings.ModuleForOptionNotFound(Option.ADD_READS, targetModule)); } continue; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java index c063058d11c9f..35b0e89c8a4dd 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java @@ -31,12 +31,10 @@ import java.util.LinkedHashMap; import java.util.EnumSet; import java.util.HashSet; -import java.util.Map.Entry; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BiPredicate; import java.util.function.Consumer; import java.util.function.Function; @@ -63,7 +61,6 @@ import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Log; -import com.sun.tools.javac.util.Name; import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Pair; @@ -428,7 +425,7 @@ private boolean currentClassIsExternallyExtendable() { int remain = warning.length; do { DiagnosticPosition pos = warning[--remain]; - log.warning(Lint.LintCategory.THIS_ESCAPE, pos, key); + log.warning(pos, key); key = Warnings.PossibleThisEscapeLocation; } while (remain > 0); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java index 3999cf0c36bb9..9b2d4e9f2a35b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java @@ -29,8 +29,6 @@ import java.io.InputStream; import java.lang.ref.SoftReference; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.nio.ByteBuffer; @@ -41,7 +39,6 @@ import java.nio.charset.CodingErrorAction; import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; -import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.util.Collection; @@ -56,13 +53,11 @@ import javax.tools.JavaFileObject; import javax.tools.JavaFileObject.Kind; -import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.main.Option; import com.sun.tools.javac.main.OptionHelper; import com.sun.tools.javac.main.OptionHelper.GrumpyHelper; import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Warnings; -import com.sun.tools.javac.util.Abort; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.DefinedBy; import com.sun.tools.javac.util.DefinedBy.Api; @@ -529,6 +524,6 @@ synchronized void newOutputToPath(Path path) throws IOException { // Check whether we've already opened this file for output if (!outputFilesWritten.add(realPath)) - log.warning(LintCategory.OUTPUT_FILE_CLASH, Warnings.OutputFileClash(path)); + log.warning(Warnings.OutputFileClash(path)); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java index 9da2052b9f3bf..98bc53b57fa2d 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java @@ -79,8 +79,6 @@ import jdk.internal.jmod.JmodFile; -import com.sun.tools.javac.code.Lint; -import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.main.Option; import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Warnings; @@ -224,7 +222,7 @@ private Iterable getPathEntries(String searchPath, Path emptyPathDefault) entries.add(getPath(s)); } catch (IllegalArgumentException e) { if (warn) { - log.warning(LintCategory.PATH, Warnings.InvalidPath(s)); + log.warning(Warnings.InvalidPath(s)); } } } @@ -319,8 +317,8 @@ public SearchPath addDirectories(String dirs) { private void addDirectory(Path dir, boolean warn) { if (!Files.isDirectory(dir)) { if (warn) { - log.warning(Lint.LintCategory.PATH, - Warnings.DirPathElementNotFound(dir)); + log.warning( + Warnings.DirPathElementNotFound(dir)); } return; } @@ -365,8 +363,8 @@ public void addFile(Path file, boolean warn) { if (!fsInfo.exists(file)) { /* No such file or directory exists */ if (warn) { - log.warning(Lint.LintCategory.PATH, - Warnings.PathElementNotFound(file)); + log.warning( + Warnings.PathElementNotFound(file)); } super.add(file); return; @@ -388,14 +386,14 @@ public void addFile(Path file, boolean warn) { try { FileSystems.newFileSystem(file, (ClassLoader)null).close(); if (warn) { - log.warning(Lint.LintCategory.PATH, - Warnings.UnexpectedArchiveFile(file)); + log.warning( + Warnings.UnexpectedArchiveFile(file)); } } catch (IOException | ProviderNotFoundException e) { // FIXME: include e.getLocalizedMessage in warning if (warn) { - log.warning(Lint.LintCategory.PATH, - Warnings.InvalidArchiveFile(file)); + log.warning( + Warnings.InvalidArchiveFile(file)); } return; } @@ -1662,7 +1660,7 @@ void add(Map> map, Path prefix, Path suffix) { Warning key = Files.exists(prefix) ? Warnings.DirPathElementNotDirectory(prefix) : Warnings.DirPathElementNotFound(prefix); - log.warning(Lint.LintCategory.PATH, key); + log.warning(key); } return; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java index f70b96697b37b..ca620219ce015 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java @@ -855,7 +855,7 @@ protected boolean accepts(AttributeKind kind) { if (lintClassfile && !warnedAttrs.contains(name)) { JavaFileObject prev = log.useSource(currentClassFile); try { - log.warning(LintCategory.CLASSFILE, (DiagnosticPosition) null, + log.warning((DiagnosticPosition) null, Warnings.FutureAttr(name, version.major, version.minor, majorVersion, minorVersion)); } finally { log.useSource(prev); @@ -1610,7 +1610,7 @@ void readParameterAnnotations(Symbol meth) { //the RuntimeVisibleParameterAnnotations and RuntimeInvisibleParameterAnnotations //provide annotations for a different number of parameters, ignore: if (lintClassfile) { - log.warning(LintCategory.CLASSFILE, Warnings.RuntimeVisibleInvisibleParamAnnotationsMismatch(currentClassFile)); + log.warning(Warnings.RuntimeVisibleInvisibleParamAnnotationsMismatch(currentClassFile)); } for (int pnum = 0; pnum < numParameters; pnum++) { readAnnotations(); @@ -2960,7 +2960,7 @@ void adjustParameterAnnotations(MethodSymbol sym, Type methodDescriptor, private void dropParameterAnnotations() { parameterAnnotations = null; if (lintClassfile) { - log.warning(LintCategory.CLASSFILE, Warnings.RuntimeInvisibleParameterAnnotations(currentClassFile)); + log.warning(Warnings.RuntimeInvisibleParameterAnnotations(currentClassFile)); } } /** diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java index 2af50832f96fc..de81ddf58577e 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java @@ -497,7 +497,7 @@ public boolean validate() { if (lintPaths) { Path outDirParent = outDir.getParent(); if (outDirParent != null && Files.exists(outDirParent.resolve("module-info.class"))) { - log.warning(LintCategory.PATH, Warnings.OutdirIsInExplodedModule(outDir)); + log.warning(Warnings.OutdirIsInExplodedModule(outDir)); } } } @@ -571,10 +571,10 @@ public boolean validate() { if (fm instanceof BaseFileManager baseFileManager) { if (source.compareTo(Source.JDK8) <= 0) { if (baseFileManager.isDefaultBootClassPath()) - log.warning(LintCategory.OPTIONS, Warnings.SourceNoBootclasspath(source.name, releaseNote(source, targetString))); + log.warning(Warnings.SourceNoBootclasspath(source.name, releaseNote(source, targetString))); } else { if (baseFileManager.isDefaultSystemModulesPath()) - log.warning(LintCategory.OPTIONS, Warnings.SourceNoSystemModulesPath(source.name, releaseNote(source, targetString))); + log.warning(Warnings.SourceNoSystemModulesPath(source.name, releaseNote(source, targetString))); } } } @@ -584,14 +584,14 @@ public boolean validate() { if (source.compareTo(Source.MIN) < 0) { log.error(Errors.OptionRemovedSource(source.name, Source.MIN.name)); } else if (source == Source.MIN && lintOptions) { - log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteSource(source.name)); + log.warning(Warnings.OptionObsoleteSource(source.name)); obsoleteOptionFound = true; } if (target.compareTo(Target.MIN) < 0) { log.error(Errors.OptionRemovedTarget(target, Target.MIN)); } else if (target == Target.MIN && lintOptions) { - log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteTarget(target)); + log.warning(Warnings.OptionObsoleteTarget(target)); obsoleteOptionFound = true; } @@ -625,7 +625,7 @@ public boolean validate() { } if (obsoleteOptionFound && lintOptions) { - log.warning(LintCategory.OPTIONS, Warnings.OptionObsoleteSuppression); + log.warning(Warnings.OptionObsoleteSuppression); } SourceVersion sv = Source.toSourceVersion(source); @@ -636,7 +636,7 @@ public boolean validate() { validateDefaultModuleForCreatedFiles(sv); if (lintOptions && options.isSet(Option.ADD_OPENS)) { - log.warning(LintCategory.OPTIONS, Warnings.AddopensIgnored); + log.warning(Warnings.AddopensIgnored); } return !errors && (log.nerrors == 0); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java index a38658a315e2d..28c443831bc41 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java @@ -35,12 +35,10 @@ import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.tree.EndPosTable; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.JCDiagnostic.*; import java.nio.CharBuffer; -import java.util.Iterator; import java.util.Set; import static com.sun.tools.javac.parser.Tokens.*; @@ -228,7 +226,7 @@ protected void lexError(DiagnosticFlag flags, int pos, JCDiagnostic.Error key) { */ protected void lexWarning(LintCategory lc, int pos, JCDiagnostic.Warning key) { DiagnosticPosition dp = new SimpleDiagnosticPosition(pos) ; - log.warning(lc, dp, key); + log.warning(dp, key); } /** diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java index d975a6c927a10..43b99f52e57bf 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -669,7 +669,7 @@ void reportDanglingDocComment(Comment c) { deferredLintHandler.report(lint -> { if (lint.isEnabled(Lint.LintCategory.DANGLING_DOC_COMMENTS) && !shebang(c, pos)) { - log.warning(Lint.LintCategory.DANGLING_DOC_COMMENTS, + log.warning( pos, Warnings.DanglingDocComment); } }); 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 1872f7d653dde..8efce29d474a4 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 @@ -2230,22 +2230,27 @@ compiler.warn.proc.package.does.not.exist=\ package {0} does not exist # 0: string +# lint: processing compiler.warn.proc.file.reopening=\ Attempt to create a file for ''{0}'' multiple times # 0: string +# lint: processing compiler.warn.proc.type.already.exists=\ A file for type ''{0}'' already exists on the sourcepath or classpath # 0: string +# lint: processing compiler.warn.proc.type.recreate=\ Attempt to create a file for type ''{0}'' multiple times # 0: string +# lint: processing compiler.warn.proc.illegal.file.name=\ Cannot create file for illegal name ''{0}''. # 0: string, 1: string +# lint: processing compiler.warn.proc.suspicious.class.name=\ Creating file for a type whose name ends in {1}: ''{0}'' @@ -2254,10 +2259,12 @@ compiler.warn.proc.file.create.last.round=\ File for type ''{0}'' created in the last round will not be subject to annotation processing. # 0: string, 1: string +# lint: processing compiler.warn.proc.malformed.supported.string=\ Malformed string ''{0}'' for a supported annotation interface returned by processor ''{1}'' # 0: set of string +# lint: processing compiler.warn.proc.annotations.without.processors=\ No processor claimed any of these annotations: {0} @@ -2266,15 +2273,18 @@ compiler.warn.proc.processor.incompatible.source.version=\ Supported source version ''{0}'' from annotation processor ''{1}'' less than -source ''{2}'' # 0: string, 1: string +# lint: processing compiler.warn.proc.duplicate.option.name=\ Duplicate supported option ''{0}'' returned by annotation processor ''{1}'' # 0: string, 1: string +# lint: processing compiler.warn.proc.duplicate.supported.annotation=\ Duplicate supported annotation interface ''{0}'' returned by annotation processor ''{1}'' # 0: string +# lint: processing compiler.warn.proc.redundant.types.with.wildcard=\ Annotation processor ''{0}'' redundantly supports both ''*'' and other annotation interfaces @@ -2401,10 +2411,12 @@ compiler.warn.empty.if=\ empty statement after if # 0: type, 1: name +# lint: classfile compiler.warn.annotation.method.not.found=\ Cannot find annotation method ''{1}()'' in type ''{0}'' # 0: type, 1: name, 2: message segment +# lint: classfile compiler.warn.annotation.method.not.found.reason=\ Cannot find annotation method ''{1}()'' in type ''{0}'': {2} diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java index 27c994538ac8f..59730448bf53a 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/AbstractLog.java @@ -29,7 +29,6 @@ import java.util.Map; import javax.tools.JavaFileObject; -import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; import com.sun.tools.javac.util.JCDiagnostic.Error; import com.sun.tools.javac.util.JCDiagnostic.Note; @@ -155,23 +154,16 @@ public void error(DiagnosticFlag flag, int pos, Error errorKey) { report(diags.error(flag, source, wrap(pos), errorKey)); } - /** Report a warning, unless suppressed by the -nowarn option or the - * maximum number of warnings has been reached. - * @param warningKey The key for the localized warning message. + /** + * Report a lint warning, unless suppressed by the -nowarn option or the + * maximum number of warnings has been reached. + * + * @param warningKey The key for the localized warning message. */ public void warning(Warning warningKey) { report(diags.warning(source, null, warningKey)); } - /** Report a lint warning, unless suppressed by the -nowarn option or the - * maximum number of warnings has been reached. - * @param lc The lint category for the diagnostic - * @param warningKey The key for the localized warning message. - */ - public void warning(LintCategory lc, Warning warningKey) { - report(diags.warning(null, null, warningKey)); - } - /** Report a warning, unless suppressed by the -nowarn option or the * maximum number of warnings has been reached. * @param pos The source position at which to report the warning. @@ -181,16 +173,6 @@ public void warning(DiagnosticPosition pos, Warning warningKey) { report(diags.warning(source, pos, warningKey)); } - /** Report a lint warning, unless suppressed by the -nowarn option or the - * maximum number of warnings has been reached. - * @param lc The lint category for the diagnostic - * @param pos The source position at which to report the warning. - * @param warningKey The key for the localized warning message. - */ - public void warning(LintCategory lc, DiagnosticPosition pos, Warning warningKey) { - report(diags.warning(source, pos, warningKey)); - } - /** Report a warning, unless suppressed by the -nowarn option or the * maximum number of warnings has been reached. * @param pos The source position at which to report the warning. @@ -208,15 +190,6 @@ public void mandatoryWarning(DiagnosticPosition pos, Warning warningKey) { report(diags.mandatoryWarning(source, pos, warningKey)); } - /** Report a warning. - * @param lc The lint category for the diagnostic - * @param pos The source position at which to report the warning. - * @param warningKey The key for the localized warning message. - */ - public void mandatoryWarning(LintCategory lc, DiagnosticPosition pos, Warning warningKey) { - report(diags.mandatoryWarning(source, pos, warningKey)); - } - /** Provide a non-fatal notification, unless suppressed by the -nowarn option. * @param noteKey The key for the localized notification message. */ diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java index 9fe9590ef35b1..36391d5ea984f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java @@ -259,9 +259,9 @@ public void reportDeferredDiagnostic() { private void logMandatoryWarning(DiagnosticPosition pos, Warning warnKey) { // Note: the following log methods are safe if lintCategory is null. if (enforceMandatory) - log.mandatoryWarning(lintCategory, pos, warnKey); + log.mandatoryWarning(pos, warnKey); else - log.warning(lintCategory, pos, warnKey); + log.warning(pos, warnKey); } /** From 06df4f7e4db4070ce8dd92d701d0cd84d79bbffc Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Mon, 2 Dec 2024 15:23:38 +0000 Subject: [PATCH 06/10] Simplify code --- .../tools/propertiesparser/parser/MessageLine.java | 1 - .../classes/com/sun/tools/javac/code/Preview.java | 2 +- .../share/classes/com/sun/tools/javac/comp/Check.java | 8 ++++---- .../com/sun/tools/javac/parser/JavaTokenizer.java | 7 +++---- .../sun/tools/javac/util/MandatoryWarningHandler.java | 11 +---------- 5 files changed, 9 insertions(+), 20 deletions(-) diff --git a/make/langtools/tools/propertiesparser/parser/MessageLine.java b/make/langtools/tools/propertiesparser/parser/MessageLine.java index 559b5c60f6497..c73021e08274e 100644 --- a/make/langtools/tools/propertiesparser/parser/MessageLine.java +++ b/make/langtools/tools/propertiesparser/parser/MessageLine.java @@ -25,7 +25,6 @@ package propertiesparser.parser; -import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java index 29b290b285e0a..baa0240365b80 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java @@ -102,7 +102,7 @@ protected Preview(Context context) { lint = Lint.instance(context); source = Source.instance(context); this.previewHandler = - new MandatoryWarningHandler(log, source, lint.isEnabled(LintCategory.PREVIEW), true, "preview", LintCategory.PREVIEW); + new MandatoryWarningHandler(log, source, lint.isEnabled(LintCategory.PREVIEW), true, "preview"); forcePreview = options.isSet("forcePreview"); majorVersionToSource = initMajorVersionToSourceMap(); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index f425b818734ff..84eb02d8a7f1d 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -167,13 +167,13 @@ protected Check(Context context) { boolean enforceMandatoryWarnings = true; deprecationHandler = new MandatoryWarningHandler(log, null, verboseDeprecated, - enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION); + enforceMandatoryWarnings, "deprecated"); removalHandler = new MandatoryWarningHandler(log, null, verboseRemoval, - enforceMandatoryWarnings, "removal", LintCategory.REMOVAL); + enforceMandatoryWarnings, "removal"); uncheckedHandler = new MandatoryWarningHandler(log, null, verboseUnchecked, - enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED); + enforceMandatoryWarnings, "unchecked"); sunApiHandler = new MandatoryWarningHandler(log, null, false, - enforceMandatoryWarnings, "sunapi", null); + enforceMandatoryWarnings, "sunapi"); deferredLintHandler = DeferredLintHandler.instance(context); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java index 28c443831bc41..a09d82aa70e1c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java @@ -220,11 +220,10 @@ protected void lexError(DiagnosticFlag flags, int pos, JCDiagnostic.Error key) { /** * Report an error at the given position using the provided arguments. * - * @param lc lint category. * @param pos position in input buffer. * @param key error key to report. */ - protected void lexWarning(LintCategory lc, int pos, JCDiagnostic.Warning key) { + protected void lexWarning(int pos, JCDiagnostic.Warning key) { DiagnosticPosition dp = new SimpleDiagnosticPosition(pos) ; log.warning(dp, key); } @@ -1073,11 +1072,11 @@ public Token readToken() { Set checks = TextBlockSupport.checkWhitespace(string); if (checks.contains(TextBlockSupport.WhitespaceChecks.INCONSISTENT)) { - lexWarning(LintCategory.TEXT_BLOCKS, pos, + lexWarning(pos, Warnings.InconsistentWhiteSpaceIndentation); } if (checks.contains(TextBlockSupport.WhitespaceChecks.TRAILING)) { - lexWarning(LintCategory.TEXT_BLOCKS, pos, + lexWarning(pos, Warnings.TrailingWhiteSpaceWillBeRemoved); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java index 36391d5ea984f..463819afa698d 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java @@ -110,17 +110,14 @@ private enum DeferredDiagnosticKind { * True if mandatory warnings and notes are being enforced. * @param prefix A common prefix for the set of message keys for * the messages that may be generated. - * @param lc An associated lint category for the warnings, or null if none. */ public MandatoryWarningHandler(Log log, Source source, boolean verbose, - boolean enforceMandatory, String prefix, - LintCategory lc) { + boolean enforceMandatory, String prefix) { this.log = log; this.source = source; this.verbose = verbose; this.prefix = prefix; this.enforceMandatory = enforceMandatory; - this.lintCategory = lc; } /** @@ -246,12 +243,6 @@ public void reportDeferredDiagnostic() { */ private final boolean enforceMandatory; - /** - * A LintCategory to be included in point-of-use diagnostics to indicate - * how messages might be suppressed (i.e. with @SuppressWarnings). - */ - private final LintCategory lintCategory; - /** * Reports a mandatory warning to the log. If mandatory warnings * are not being enforced, treat this as an ordinary warning. From c49f7a57148c64ae61cd9a4f1304d66e4e7fd5a1 Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Wed, 4 Dec 2024 16:58:49 +0000 Subject: [PATCH 07/10] Separate LintWarnings from Warnings in CompilerProperties Add Lint::logIfEnabled --- .../propertiesparser/gen/ClassGenerator.java | 26 ++- .../resources/templates.properties | 1 + .../com/sun/tools/javac/code/Lint.java | 15 ++ .../com/sun/tools/javac/code/Preview.java | 12 +- .../com/sun/tools/javac/comp/Attr.java | 25 ++- .../com/sun/tools/javac/comp/Check.java | 173 +++++++----------- .../com/sun/tools/javac/comp/Flow.java | 16 +- .../com/sun/tools/javac/comp/Modules.java | 11 +- .../tools/javac/comp/ThisEscapeAnalyzer.java | 5 +- .../sun/tools/javac/file/BaseFileManager.java | 3 +- .../com/sun/tools/javac/file/Locations.java | 16 +- .../com/sun/tools/javac/jvm/ClassReader.java | 11 +- .../com/sun/tools/javac/main/Arguments.java | 15 +- .../sun/tools/javac/parser/JavaTokenizer.java | 5 +- .../sun/tools/javac/parser/JavacParser.java | 3 +- .../tools/javac/processing/JavacFiler.java | 11 +- .../JavacProcessingEnvironment.java | 11 +- .../tools/javac/resources/compiler.properties | 5 + .../sun/tools/javac/util/JCDiagnostic.java | 33 ++-- .../javac/util/MandatoryWarningHandler.java | 15 +- .../tools/javac/6304921/TestLog.java | 10 +- 21 files changed, 225 insertions(+), 197 deletions(-) diff --git a/make/langtools/tools/propertiesparser/gen/ClassGenerator.java b/make/langtools/tools/propertiesparser/gen/ClassGenerator.java index 079d01cee1937..e869d60bbc569 100644 --- a/make/langtools/tools/propertiesparser/gen/ClassGenerator.java +++ b/make/langtools/tools/propertiesparser/gen/ClassGenerator.java @@ -48,6 +48,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.TreeMap; @@ -117,6 +118,7 @@ String format(Object... args) { enum FactoryKind { ERR("err", "Error", "Errors"), WARN("warn", "Warning", "Warnings"), + LINT_WARN("warn", "LintWarning", "LintWarnings"), NOTE("note", "Note", "Notes"), MISC("misc", "Fragment", "Fragments"), OTHER(null, null, null); @@ -139,13 +141,24 @@ enum FactoryKind { /** * Utility method for parsing a factory kind from a resource key prefix. */ - static FactoryKind parseFrom(String prefix) { + static FactoryKind of(Entry messageEntry) { + String prefix = messageEntry.getKey().split("\\.")[1]; + FactoryKind selected = null; for (FactoryKind k : FactoryKind.values()) { if (k.prefix == null || k.prefix.equals(prefix)) { - return k; + selected = k; + break; } } - return null; + if (selected == WARN) { + for (MessageLine line : messageEntry.getValue().getLines(false)) { + if (line.isLint()) { + selected = LINT_WARN; + break; + } + } + } + return selected; } } @@ -158,7 +171,7 @@ public void generateFactory(MessageFile messageFile, File outDir) { messageFile.messages.entrySet().stream() .collect( Collectors.groupingBy( - e -> FactoryKind.parseFrom(e.getKey().split("\\.")[1]), + FactoryKind::of, TreeMap::new, toList())); //generate nested classes @@ -168,7 +181,7 @@ public void generateFactory(MessageFile messageFile, File outDir) { if (entry.getKey() == FactoryKind.OTHER) continue; //emit members String members = entry.getValue().stream() - .flatMap(e -> generateFactoryMethodsAndFields(e.getKey(), e.getValue()).stream()) + .flatMap(e -> generateFactoryMethodsAndFields(entry.getKey(), e.getKey(), e.getValue()).stream()) .collect(Collectors.joining("\n\n")); //emit nested class String factoryDecl = @@ -233,7 +246,7 @@ List generateImports(Set importedTypes) { /** * Generate a list of factory methods/fields to be added to a given factory nested class. */ - List generateFactoryMethodsAndFields(String key, Message msg) { + List generateFactoryMethodsAndFields(FactoryKind k, String key, Message msg) { MessageInfo msgInfo = msg.getMessageInfo(); List lines = msg.getLines(false); String javadoc = lines.stream() @@ -241,7 +254,6 @@ List generateFactoryMethodsAndFields(String key, Message msg) { .map(ml -> ml.text) .collect(Collectors.joining("\n *")); String[] keyParts = key.split("\\."); - FactoryKind k = FactoryKind.parseFrom(keyParts[1]); String lintCategory = lines.stream() .filter(MessageLine::isLint) .map(MessageLine::lintCategory) diff --git a/make/langtools/tools/propertiesparser/resources/templates.properties b/make/langtools/tools/propertiesparser/resources/templates.properties index 44f6248cf0040..bb403238f804b 100644 --- a/make/langtools/tools/propertiesparser/resources/templates.properties +++ b/make/langtools/tools/propertiesparser/resources/templates.properties @@ -29,6 +29,7 @@ toplevel.decl=\ {1}\n\ import com.sun.tools.javac.util.JCDiagnostic.Error;\n\ import com.sun.tools.javac.util.JCDiagnostic.Warning;\n\ + import com.sun.tools.javac.util.JCDiagnostic.LintWarning;\n\ import com.sun.tools.javac.util.JCDiagnostic.Note;\n\ import com.sun.tools.javac.util.JCDiagnostic.Fragment;\n\ import com.sun.tools.javac.code.Lint.LintCategory;\n\ 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 af2d98d6c11ae..e46b58b0954ea 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 @@ -33,7 +33,10 @@ import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.main.Option; import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; +import com.sun.tools.javac.util.JCDiagnostic.LintWarning; import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Pair; @@ -93,6 +96,7 @@ public Lint suppress(LintCategory... lc) { return l; } + private final Log log; private final AugmentVisitor augmentor; private final EnumSet values; @@ -146,12 +150,14 @@ protected Lint(Context context) { context.put(lintKey, this); augmentor = new AugmentVisitor(context); + log = Log.instance(context); } protected Lint(Lint other) { this.augmentor = other.augmentor; this.values = other.values.clone(); this.suppressedValues = other.suppressedValues.clone(); + this.log = other.log; } @Override @@ -385,6 +391,15 @@ public boolean isSuppressed(LintCategory lc) { return suppressedValues.contains(lc); } + /** + * Helper method. Log a lint warning if its lint category is enabled. + */ + public void logIfEnabled(DiagnosticPosition pos, LintWarning warning) { + if (isEnabled(warning.getLintCategory())) { + log.warning(pos, warning); + } + } + protected static class AugmentVisitor implements Attribute.Visitor { private final Context context; private Symtab syms; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java index baa0240365b80..5a684a1cc59bd 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java @@ -30,11 +30,13 @@ import com.sun.tools.javac.code.Symbol.ModuleSymbol; import com.sun.tools.javac.jvm.Target; import com.sun.tools.javac.resources.CompilerProperties.Errors; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.util.Assert; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.Error; +import com.sun.tools.javac.util.JCDiagnostic.LintWarning; import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.Warning; import com.sun.tools.javac.util.Log; @@ -102,7 +104,7 @@ protected Preview(Context context) { lint = Lint.instance(context); source = Source.instance(context); this.previewHandler = - new MandatoryWarningHandler(log, source, lint.isEnabled(LintCategory.PREVIEW), true, "preview"); + new MandatoryWarningHandler(log, source, lint.isEnabled(LintCategory.PREVIEW), true, "preview", LintCategory.PREVIEW); forcePreview = options.isSet("forcePreview"); majorVersionToSource = initMajorVersionToSourceMap(); } @@ -175,8 +177,8 @@ public void warnPreview(DiagnosticPosition pos, Feature feature) { if (!lint.isSuppressed(LintCategory.PREVIEW)) { sourcesWithPreviewFeatures.add(log.currentSourceFile()); previewHandler.report(pos, feature.isPlural() ? - Warnings.PreviewFeatureUsePlural(feature.nameFragment()) : - Warnings.PreviewFeatureUse(feature.nameFragment())); + LintWarnings.PreviewFeatureUsePlural(feature.nameFragment()) : + LintWarnings.PreviewFeatureUse(feature.nameFragment())); } } @@ -189,7 +191,7 @@ public void warnPreview(JavaFileObject classfile, int majorVersion) { Assert.check(isEnabled()); if (lint.isEnabled(LintCategory.PREVIEW)) { log.mandatoryWarning(null, - Warnings.PreviewFeatureUseClassfile(classfile, majorVersionToSource.get(majorVersion).name)); + LintWarnings.PreviewFeatureUseClassfile(classfile, majorVersionToSource.get(majorVersion).name)); } } @@ -197,7 +199,7 @@ public void markUsesPreview(DiagnosticPosition pos) { sourcesWithPreviewFeatures.add(log.currentSourceFile()); } - public void reportPreviewWarning(DiagnosticPosition pos, Warning warnKey) { + public void reportPreviewWarning(DiagnosticPosition pos, LintWarning warnKey) { previewHandler.report(pos, warnKey); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index a18f82613e0f8..b66e6525dc651 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -58,6 +58,7 @@ import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Fragments; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.*; @@ -1938,8 +1939,8 @@ private Symbol enumConstant(JCTree tree, Type enumType) { public void visitSynchronized(JCSynchronized tree) { chk.checkRefType(tree.pos(), attribExpr(tree.lock, env)); - if (env.info.lint.isEnabled(LintCategory.SYNCHRONIZATION) && isValueBased(tree.lock.type)) { - log.warning(tree.pos(), Warnings.AttemptToSynchronizeOnInstanceOfValueBasedClass); + if (isValueBased(tree.lock.type)) { + env.info.lint.logIfEnabled(tree.pos(), LintWarnings.AttemptToSynchronizeOnInstanceOfValueBasedClass); } attribStat(tree.body, env); result = null; @@ -2045,9 +2046,8 @@ void checkAutoCloseable(DiagnosticPosition pos, Env env, Type resou } if (close.kind == MTH && close.overrides(syms.autoCloseableClose, resource.tsym, types, true) && - chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes()) && - env.info.lint.isEnabled(LintCategory.TRY)) { - log.warning(pos, Warnings.TryResourceThrowsInterruptedExc(resource)); + chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes())) { + env.info.lint.logIfEnabled(pos, LintWarnings.TryResourceThrowsInterruptedExc(resource)); } } } @@ -4441,9 +4441,8 @@ public void visitSelect(JCFieldAccess tree) { ((VarSymbol)sitesym).isResourceVariable() && sym.kind == MTH && sym.name.equals(names.close) && - sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true) && - env.info.lint.isEnabled(LintCategory.TRY)) { - log.warning(tree, Warnings.TryExplicitCloseCall); + sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true)) { + env.info.lint.logIfEnabled(tree, LintWarnings.TryExplicitCloseCall); } // Disallow selecting a type from an expression @@ -4470,9 +4469,9 @@ public void visitSelect(JCFieldAccess tree) { // If the qualified item is not a type and the selected item is static, report // a warning. Make allowance for the class of an array type e.g. Object[].class) if (!sym.owner.isAnonymous()) { - chk.warnStatic(tree, Warnings.StaticNotQualifiedByType(sym.kind.kindName(), sym.owner)); + env.info.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType(sym.kind.kindName(), sym.owner)); } else { - chk.warnStatic(tree, Warnings.StaticNotQualifiedByType2(sym.kind.kindName())); + env.info.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType2(sym.kind.kindName())); } } @@ -4685,7 +4684,7 @@ else if (ownOuter.hasTag(CLASS) && site != ownOuter) { if (s != null && s.isRaw() && !types.isSameType(v.type, v.erasure(types))) { - chk.warnUnchecked(tree.pos(), Warnings.UncheckedAssignToVar(v, s)); + chk.warnUnchecked(tree.pos(), LintWarnings.UncheckedAssignToVar(v, s)); } } // The computed type of a variable is the type of the @@ -4883,7 +4882,7 @@ public Type checkMethod(Type site, if (s != null && s.isRaw() && !types.isSameTypes(sym.type.getParameterTypes(), sym.erasure(types).getParameterTypes())) { - chk.warnUnchecked(env.tree.pos(), Warnings.UncheckedCallMbrOfRawType(sym, s)); + chk.warnUnchecked(env.tree.pos(), LintWarnings.UncheckedCallMbrOfRawType(sym, s)); } } @@ -4933,7 +4932,7 @@ public Type checkMethod(Type site, argtypes = argtypes.map(checkDeferredMap); if (noteWarner.hasNonSilentLint(LintCategory.UNCHECKED)) { - chk.warnUnchecked(env.tree.pos(), Warnings.UncheckedMethInvocationApplied(kindName(sym), + chk.warnUnchecked(env.tree.pos(), LintWarnings.UncheckedMethInvocationApplied(kindName(sym), sym.name, rs.methodArguments(sym.type.getParameterTypes()), rs.methodArguments(argtypes.map(checkDeferredMap)), diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index 84eb02d8a7f1d..8f91dcde16515 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -49,12 +49,14 @@ import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Fragments; import com.sun.tools.javac.resources.CompilerProperties.Warnings; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.JCDiagnostic.Error; import com.sun.tools.javac.util.JCDiagnostic.Fragment; +import com.sun.tools.javac.util.JCDiagnostic.LintWarning; import com.sun.tools.javac.util.JCDiagnostic.Warning; import com.sun.tools.javac.util.List; @@ -167,13 +169,13 @@ protected Check(Context context) { boolean enforceMandatoryWarnings = true; deprecationHandler = new MandatoryWarningHandler(log, null, verboseDeprecated, - enforceMandatoryWarnings, "deprecated"); + enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION); removalHandler = new MandatoryWarningHandler(log, null, verboseRemoval, - enforceMandatoryWarnings, "removal"); + enforceMandatoryWarnings, "removal", LintCategory.REMOVAL); uncheckedHandler = new MandatoryWarningHandler(log, null, verboseUnchecked, - enforceMandatoryWarnings, "unchecked"); + enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED); sunApiHandler = new MandatoryWarningHandler(log, null, false, - enforceMandatoryWarnings, "sunapi"); + enforceMandatoryWarnings, "sunapi", null); deferredLintHandler = DeferredLintHandler.instance(context); @@ -247,16 +249,16 @@ void warnDeprecated(DiagnosticPosition pos, Symbol sym) { if (sym.isDeprecatedForRemoval()) { if (!lint.isSuppressed(LintCategory.REMOVAL)) { if (sym.kind == MDL) { - removalHandler.report(pos, Warnings.HasBeenDeprecatedForRemovalModule(sym)); + removalHandler.report(pos, LintWarnings.HasBeenDeprecatedForRemovalModule(sym)); } else { - removalHandler.report(pos, Warnings.HasBeenDeprecatedForRemoval(sym, sym.location())); + removalHandler.report(pos, LintWarnings.HasBeenDeprecatedForRemoval(sym, sym.location())); } } } else if (!lint.isSuppressed(LintCategory.DEPRECATION)) { if (sym.kind == MDL) { - deprecationHandler.report(pos, Warnings.HasBeenDeprecatedModule(sym)); + deprecationHandler.report(pos, LintWarnings.HasBeenDeprecatedModule(sym)); } else { - deprecationHandler.report(pos, Warnings.HasBeenDeprecated(sym, sym.location())); + deprecationHandler.report(pos, LintWarnings.HasBeenDeprecated(sym, sym.location())); } } } @@ -265,7 +267,7 @@ void warnDeprecated(DiagnosticPosition pos, Symbol sym) { * @param pos Position to be used for error reporting. * @param msg A Warning describing the problem. */ - public void warnPreviewAPI(DiagnosticPosition pos, Warning warnKey) { + public void warnPreviewAPI(DiagnosticPosition pos, LintWarning warnKey) { if (!lint.isSuppressed(LintCategory.PREVIEW)) preview.reportPreviewWarning(pos, warnKey); } @@ -276,7 +278,7 @@ public void warnPreviewAPI(DiagnosticPosition pos, Warning warnKey) { */ public void warnDeclaredUsingPreview(DiagnosticPosition pos, Symbol sym) { if (!lint.isSuppressed(LintCategory.PREVIEW)) - preview.reportPreviewWarning(pos, Warnings.DeclaredUsingPreview(kindName(sym), sym)); + preview.reportPreviewWarning(pos, LintWarnings.DeclaredUsingPreview(kindName(sym), sym)); } /** Log a preview warning. @@ -284,40 +286,18 @@ public void warnDeclaredUsingPreview(DiagnosticPosition pos, Symbol sym) { * @param msg A Warning describing the problem. */ public void warnRestrictedAPI(DiagnosticPosition pos, Symbol sym) { - if (lint.isEnabled(LintCategory.RESTRICTED)) - log.warning(pos, Warnings.RestrictedMethod(sym.enclClass(), sym)); + lint.logIfEnabled(pos, LintWarnings.RestrictedMethod(sym.enclClass(), sym)); } /** Warn about unchecked operation. * @param pos Position to be used for error reporting. * @param msg A string describing the problem. */ - public void warnUnchecked(DiagnosticPosition pos, Warning warnKey) { + public void warnUnchecked(DiagnosticPosition pos, LintWarning warnKey) { if (!lint.isSuppressed(LintCategory.UNCHECKED)) uncheckedHandler.report(pos, warnKey); } - /** Warn about unsafe vararg method decl. - * @param pos Position to be used for error reporting. - */ - void warnUnsafeVararg(DiagnosticPosition pos, Warning warnKey) { - if (lint.isEnabled(LintCategory.VARARGS)) - log.warning(pos, warnKey); - } - - public void warnStatic(DiagnosticPosition pos, Warning warnKey) { - if (lint.isEnabled(LintCategory.STATIC)) - log.warning(pos, warnKey); - } - - /** Warn about division by integer constant zero. - * @param pos Position to be used for error reporting. - */ - void warnDivZero(DiagnosticPosition pos) { - if (lint.isEnabled(LintCategory.DIVZERO)) - log.warning(pos, Warnings.DivZero); - } - /** * Report any deferred diagnostics. */ @@ -670,9 +650,7 @@ public void checkRedundantCast(Env env, final JCTypeCast tree) { && !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz)) && !is292targetTypeCast(tree)) { deferredLintHandler.report(_l -> { - if (lint.isEnabled(LintCategory.CAST)) - log.warning( - tree.pos(), Warnings.RedundantCast(tree.clazz.type)); + lint.logIfEnabled(tree.pos(), LintWarnings.RedundantCast(tree.clazz.type)); }); } } @@ -977,13 +955,13 @@ void checkVarargsMethodDecl(Env env, JCMethodDecl tree) { } } else if (hasTrustMeAnno && varargElemType != null && types.isReifiable(varargElemType)) { - warnUnsafeVararg(tree, Warnings.VarargsRedundantTrustmeAnno( + lint.logIfEnabled(tree, LintWarnings.VarargsRedundantTrustmeAnno( syms.trustMeType.tsym, diags.fragment(Fragments.VarargsTrustmeOnReifiableVarargs(varargElemType)))); } else if (!hasTrustMeAnno && varargElemType != null && !types.isReifiable(varargElemType)) { - warnUnchecked(tree.params.head.pos(), Warnings.UncheckedVarargsNonReifiableType(varargElemType)); + warnUnchecked(tree.params.head.pos(), LintWarnings.UncheckedVarargsNonReifiableType(varargElemType)); } } //where @@ -1070,7 +1048,7 @@ Type checkMethod(final Type mtype, if (!types.isReifiable(argtype) && (sym.baseSymbol().attribute(syms.trustMeType.tsym) == null || !isTrustMeAllowedOnMethod(sym))) { - warnUnchecked(env.tree.pos(), Warnings.UncheckedGenericArrayCreation(argtype)); + warnUnchecked(env.tree.pos(), LintWarnings.UncheckedGenericArrayCreation(argtype)); } TreeInfo.setVarargsElement(env.tree, types.elemtype(argtype)); } @@ -1346,10 +1324,8 @@ && checkDisjoint(pos, flags, private void warnOnExplicitStrictfp(DiagnosticPosition pos) { DiagnosticPosition prevLintPos = deferredLintHandler.setPos(pos); try { - deferredLintHandler.report(_l -> { - if (lint.isEnabled(LintCategory.STRICTFP)) { - log.warning( - pos, Warnings.Strictfp); } + deferredLintHandler.report(_ -> { + lint.logIfEnabled(pos, LintWarnings.Strictfp); }); } finally { deferredLintHandler.setPos(prevLintPos); @@ -1565,13 +1541,11 @@ public void validateTrees(List trees, boolean checkRaw, boolea } void checkRaw(JCTree tree, Env env) { - if (lint.isEnabled(LintCategory.RAW) && - tree.type.hasTag(CLASS) && + if (tree.type.hasTag(CLASS) && !TreeInfo.isDiamond(tree) && !withinAnonConstr(env) && tree.type.isRaw()) { - log.warning( - tree.pos(), Warnings.RawClassUse(tree.type, tree.type.tsym.type)); + lint.logIfEnabled(tree.pos(), LintWarnings.RawClassUse(tree.type, tree.type.tsym.type)); } } //where @@ -1873,7 +1847,7 @@ void checkOverride(JCTree tree, return; } else if (overrideWarner.hasNonSilentLint(LintCategory.UNCHECKED)) { warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), - Warnings.OverrideUncheckedRet(uncheckedOverrides(m, other), mtres, otres)); + LintWarnings.OverrideUncheckedRet(uncheckedOverrides(m, other), mtres, otres)); } // Error if overriding method throws an exception not reported @@ -1889,17 +1863,16 @@ void checkOverride(JCTree tree, } else if (unhandledUnerased.nonEmpty()) { warnUnchecked(TreeInfo.diagnosticPositionFor(m, tree), - Warnings.OverrideUncheckedThrown(cannotOverride(m, other), unhandledUnerased.head)); + LintWarnings.OverrideUncheckedThrown(cannotOverride(m, other), unhandledUnerased.head)); return; } // Optional warning if varargs don't agree - if ((((m.flags() ^ other.flags()) & Flags.VARARGS) != 0) - && lint.isEnabled(LintCategory.OVERRIDES)) { - log.warning(TreeInfo.diagnosticPositionFor(m, tree), + if ((((m.flags() ^ other.flags()) & Flags.VARARGS) != 0)) { + lint.logIfEnabled(TreeInfo.diagnosticPositionFor(m, tree), ((m.flags() & Flags.VARARGS) != 0) - ? Warnings.OverrideVarargsMissing(varargsOverrides(m, other)) - : Warnings.OverrideVarargsExtra(varargsOverrides(m, other))); + ? LintWarnings.OverrideVarargsMissing(varargsOverrides(m, other)) + : LintWarnings.OverrideVarargsExtra(varargsOverrides(m, other))); } // Warn if instance method overrides bridge method (compiler spec ??) @@ -2244,7 +2217,7 @@ private void checkClassOverrideEqualsAndHash(DiagnosticPosition pos, if (overridesEquals && !overridesHashCode) { log.warning(pos, - Warnings.OverrideEqualsButNotHashcode(someClass)); + LintWarnings.OverrideEqualsButNotHashcode(someClass)); } } } @@ -2306,7 +2279,7 @@ public void checkModuleName (JCModuleDecl tree) { String moduleNameComponentString = componentName.toString(); int nameLength = moduleNameComponentString.length(); if (nameLength > 0 && Character.isDigit(moduleNameComponentString.charAt(nameLength - 1))) { - log.warning(pos, Warnings.PoorChoiceForModuleName(componentName)); + log.warning(pos, LintWarnings.PoorChoiceForModuleName(componentName)); } } } @@ -2778,7 +2751,7 @@ void checkPotentiallyAmbiguousOverloads(JCClassDecl tree, Type site) { // Log the warning log.warning(pos, - Warnings.PotentiallyAmbiguousOverload( + LintWarnings.PotentiallyAmbiguousOverload( m1.asMemberOf(site, types), m1.location(), m2.asMemberOf(site, types), m2.location())); @@ -3786,14 +3759,13 @@ void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) { (s.flags() & DEPRECATED) != 0 && !syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) == null) { - log.warning( - pos, Warnings.MissingDeprecatedAnnotation); + log.warning(pos, LintWarnings.MissingDeprecatedAnnotation); } // Note: @Deprecated has no effect on local variables, parameters and package decls. if (lint.isEnabled(LintCategory.DEPRECATION) && !s.isDeprecatableViaAnnotation()) { if (!syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) != null) { log.warning(pos, - Warnings.DeprecatedAnnotationHasNoEffect(Kinds.kindName(s))); + LintWarnings.DeprecatedAnnotationHasNoEffect(Kinds.kindName(s))); } } } @@ -3853,10 +3825,10 @@ void checkPreview(DiagnosticPosition pos, Symbol other, Type site, Symbol s) { log.error(pos, Errors.IsPreview(s)); } else { preview.markUsesPreview(pos); - deferredLintHandler.report(_l -> warnPreviewAPI(pos, Warnings.IsPreview(s))); + deferredLintHandler.report(_l -> warnPreviewAPI(pos, LintWarnings.IsPreview(s))); } } else { - deferredLintHandler.report(_l -> warnPreviewAPI(pos, Warnings.IsPreviewReflective(s))); + deferredLintHandler.report(_l -> warnPreviewAPI(pos, LintWarnings.IsPreviewReflective(s))); } } if (preview.declaredUsingPreviewFeature(s)) { @@ -4121,7 +4093,7 @@ void checkDivZero(final DiagnosticPosition pos, Symbol operator, Type operand) { int opc = ((OperatorSymbol)operator).opcode; if (opc == ByteCodes.idiv || opc == ByteCodes.imod || opc == ByteCodes.ldiv || opc == ByteCodes.lmod) { - deferredLintHandler.report(_l -> warnDivZero(pos)); + deferredLintHandler.report(_ -> lint.logIfEnabled(pos, LintWarnings.DivZero)); } } } @@ -4134,10 +4106,8 @@ void checkDivZero(final DiagnosticPosition pos, Symbol operator, Type operand) { */ void checkLossOfPrecision(final DiagnosticPosition pos, Type found, Type req) { if (found.isNumeric() && req.isNumeric() && !types.isAssignable(found, req)) { - deferredLintHandler.report(_l -> { - if (lint.isEnabled(LintCategory.LOSSY_CONVERSIONS)) - log.warning( - pos, Warnings.PossibleLossOfPrecision(found, req)); + deferredLintHandler.report(_ -> { + lint.logIfEnabled(pos, LintWarnings.PossibleLossOfPrecision(found, req)); }); } } @@ -4146,9 +4116,9 @@ void checkLossOfPrecision(final DiagnosticPosition pos, Type found, Type req) { * Check for empty statements after if */ void checkEmptyIf(JCIf tree) { - if (tree.thenpart.hasTag(SKIP) && tree.elsepart == null && - lint.isEnabled(LintCategory.EMPTY)) - log.warning(tree.thenpart.pos(), Warnings.EmptyIf); + if (tree.thenpart.hasTag(SKIP) && tree.elsepart == null) { + lint.logIfEnabled(tree.thenpart.pos(), LintWarnings.EmptyIf); + } } /** Check that symbol is unique in given scope. @@ -4290,13 +4260,12 @@ private boolean isCanonical(JCTree tree) { /** Check that an auxiliary class is not accessed from any other file than its own. */ void checkForBadAuxiliaryClassAccess(DiagnosticPosition pos, Env env, ClassSymbol c) { - if (lint.isEnabled(Lint.LintCategory.AUXILIARYCLASS) && - (c.flags() & AUXILIARY) != 0 && + if ((c.flags() & AUXILIARY) != 0 && rs.isAccessible(env, c) && !fileManager.isSameFile(c.sourcefile, env.toplevel.sourcefile)) { - log.warning(pos, - Warnings.AuxiliaryClassAccessedFromOutsideOfItsSourceFile(c, c.sourcefile)); + lint.logIfEnabled(pos, + LintWarnings.AuxiliaryClassAccessedFromOutsideOfItsSourceFile(c, c.sourcefile)); } } @@ -4338,11 +4307,9 @@ void checkDefaultConstructor(ClassSymbol c, DiagnosticPosition pos) { // Warning may be suppressed by // annotations; check again for being // enabled in the deferred context. - deferredLintHandler.report(_l -> { - if (lint.isEnabled(LintCategory.MISSING_EXPLICIT_CTOR)) - log.warning( - pos, Warnings.MissingExplicitCtor(c, pkg, modle)); - }); + deferredLintHandler.report(_ -> { + lint.logIfEnabled(pos, LintWarnings.MissingExplicitCtor(c, pkg, modle)); + }); } else { return; } @@ -4371,14 +4338,14 @@ public void warn(LintCategory lint) { if (warned) return; // suppress redundant diagnostics switch (lint) { case UNCHECKED: - Check.this.warnUnchecked(pos(), Warnings.ProbFoundReq(diags.fragment(uncheckedKey), found, expected)); + Check.this.warnUnchecked(pos(), LintWarnings.ProbFoundReq(diags.fragment(uncheckedKey), found, expected)); break; case VARARGS: if (method != null && method.attribute(syms.trustMeType.tsym) != null && isTrustMeAllowedOnMethod(method) && !types.isReifiable(method.type.getParameterTypes().last())) { - Check.this.warnUnsafeVararg(pos(), Warnings.VarargsUnsafeUseVarargsParam(method.params.last())); + Check.this.lint.logIfEnabled(pos(), LintWarnings.VarargsUnsafeUseVarargsParam(method.params.last())); } break; default: @@ -4633,7 +4600,7 @@ private boolean isAPISymbol(Symbol sym) { } private void checkVisible(DiagnosticPosition pos, Symbol what, PackageSymbol inPackage, boolean inSuperType) { if (!isAPISymbol(what) && !inSuperType) { //package private/private element - log.warning(pos, Warnings.LeaksNotAccessible(kindName(what), what, what.packge().modle)); + log.warning(pos, LintWarnings.LeaksNotAccessible(kindName(what), what, what.packge().modle)); return ; } @@ -4642,13 +4609,13 @@ private void checkVisible(DiagnosticPosition pos, Symbol what, PackageSymbol inP ExportsDirective inExport = findExport(inPackage); if (whatExport == null) { //package not exported: - log.warning(pos, Warnings.LeaksNotAccessibleUnexported(kindName(what), what, what.packge().modle)); + log.warning(pos, LintWarnings.LeaksNotAccessibleUnexported(kindName(what), what, what.packge().modle)); return ; } if (whatExport.modules != null) { if (inExport.modules == null || !whatExport.modules.containsAll(inExport.modules)) { - log.warning(pos, Warnings.LeaksNotAccessibleUnexportedQualified(kindName(what), what, what.packge().modle)); + log.warning(pos, LintWarnings.LeaksNotAccessibleUnexportedQualified(kindName(what), what, what.packge().modle)); } } @@ -4670,15 +4637,14 @@ private void checkVisible(DiagnosticPosition pos, Symbol what, PackageSymbol inP } } - log.warning(pos, Warnings.LeaksNotAccessibleNotRequiredTransitive(kindName(what), what, what.packge().modle)); + log.warning(pos, LintWarnings.LeaksNotAccessibleNotRequiredTransitive(kindName(what), what, what.packge().modle)); } } void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) { if (msym.kind != MDL) { - deferredLintHandler.report(_l -> { - if (lint.isEnabled(LintCategory.MODULE)) - log.warning(pos, Warnings.ModuleNotFound(msym)); + deferredLintHandler.report(_ -> { + lint.logIfEnabled(pos, LintWarnings.ModuleNotFound(msym)); }); } } @@ -4686,20 +4652,19 @@ void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) { void checkPackageExistsForOpens(final DiagnosticPosition pos, PackageSymbol packge) { if (packge.members().isEmpty() && ((packge.flags() & Flags.HAS_RESOURCE) == 0)) { - deferredLintHandler.report(_l -> { - if (lint.isEnabled(LintCategory.OPENS)) - log.warning(pos, Warnings.PackageEmptyOrNotFound(packge)); + deferredLintHandler.report(_ -> { + lint.logIfEnabled(pos, LintWarnings.PackageEmptyOrNotFound(packge)); }); } } void checkModuleRequires(final DiagnosticPosition pos, final RequiresDirective rd) { if ((rd.module.flags() & Flags.AUTOMATIC_MODULE) != 0) { - deferredLintHandler.report(_l -> { + deferredLintHandler.report(_ -> { if (rd.isTransitive() && lint.isEnabled(LintCategory.REQUIRES_TRANSITIVE_AUTOMATIC)) { - log.warning(pos, Warnings.RequiresTransitiveAutomatic); - } else if (lint.isEnabled(LintCategory.REQUIRES_AUTOMATIC)) { - log.warning(pos, Warnings.RequiresAutomatic); + log.warning(pos, LintWarnings.RequiresTransitiveAutomatic); + } else { + lint.logIfEnabled(pos, LintWarnings.RequiresAutomatic); } }); } @@ -5303,13 +5268,13 @@ void checkPrivateNonStaticMethod(JCClassDecl tree, MethodSymbol method) { if ((flags & PRIVATE) == 0) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.SerialMethodNotPrivate(method.getSimpleName())); + LintWarnings.SerialMethodNotPrivate(method.getSimpleName())); } if ((flags & STATIC) != 0) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.SerialMethodStatic(method.getSimpleName())); + LintWarnings.SerialMethodStatic(method.getSimpleName())); } } @@ -5550,7 +5515,7 @@ void checkConcreteInstanceMethod(JCClassDecl tree, if ((method.flags() & (STATIC | ABSTRACT)) != 0) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.SerialConcreteInstanceMethod(method.getSimpleName())); + LintWarnings.SerialConcreteInstanceMethod(method.getSimpleName())); } } @@ -5567,7 +5532,7 @@ private void checkReturnType(JCClassDecl tree, if (!types.isSameType(expectedReturnType, rtype)) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.SerialMethodUnexpectedReturnType(method.getSimpleName(), + LintWarnings.SerialMethodUnexpectedReturnType(method.getSimpleName(), rtype, expectedReturnType)); } } @@ -5583,7 +5548,7 @@ private void checkOneArg(JCClassDecl tree, if (parameters.size() != 1) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.SerialMethodOneArg(method.getSimpleName(), parameters.size())); + LintWarnings.SerialMethodOneArg(method.getSimpleName(), parameters.size())); return; } @@ -5591,7 +5556,7 @@ private void checkOneArg(JCClassDecl tree, if (!types.isSameType(parameterType, expectedType)) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.SerialMethodParameterType(method.getSimpleName(), + LintWarnings.SerialMethodParameterType(method.getSimpleName(), expectedType, parameterType)); } @@ -5612,7 +5577,7 @@ private void checkNoArgs(JCClassDecl tree, Element enclosing, MethodSymbol metho if (!parameters.isEmpty()) { log.warning( TreeInfo.diagnosticPositionFor(parameters.get(0), tree), - Warnings.SerialMethodNoArgs(method.getSimpleName())); + LintWarnings.SerialMethodNoArgs(method.getSimpleName())); } } @@ -5650,7 +5615,7 @@ private void checkExceptions(JCClassDecl tree, if (!declared) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.SerialMethodUnexpectedException(method.getSimpleName(), + LintWarnings.SerialMethodUnexpectedException(method.getSimpleName(), thrownType)); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java index 8a90dc88fa90d..abcca6fe3aea2 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java @@ -38,6 +38,7 @@ import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Scope.WriteableScope; import com.sun.tools.javac.resources.CompilerProperties.Errors; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.util.*; @@ -723,11 +724,9 @@ public void visitSwitch(JCSwitch tree) { } // Warn about fall-through if lint switch fallthrough enabled. if (alive == Liveness.ALIVE && - lint.isEnabled(Lint.LintCategory.FALLTHROUGH) && c.stats.nonEmpty() && l.tail.nonEmpty()) - log.warning( - l.tail.head.pos(), - Warnings.PossibleFallThroughIntoCase); + lint.logIfEnabled(l.tail.head.pos(), + LintWarnings.PossibleFallThroughIntoCase); } tree.isExhaustive = tree.hasUnconditionalPattern || TreeInfo.isErrorEnumSwitch(tree.selector, tree.cases); @@ -1234,11 +1233,8 @@ public void visitTry(JCTry tree) { scanStat(tree.finalizer); tree.finallyCanCompleteNormally = alive != Liveness.DEAD; if (alive == Liveness.DEAD) { - if (lint.isEnabled(Lint.LintCategory.FINALLY)) { - log.warning( - TreeInfo.diagEndPos(tree.finalizer), - Warnings.FinallyCannotComplete); - } + lint.logIfEnabled(TreeInfo.diagEndPos(tree.finalizer), + LintWarnings.FinallyCannotComplete); } else { while (exits.nonEmpty()) { pendingExits.append(exits.next()); @@ -2861,7 +2857,7 @@ public void visitTry(JCTry tree) { for (JCVariableDecl resVar : resourceVarDecls) { if (unrefdResources.includes(resVar.sym) && !resVar.sym.isUnnamedVariable()) { log.warning(resVar.pos(), - Warnings.TryResourceNotReferenced(resVar.sym)); + LintWarnings.TryResourceNotReferenced(resVar.sym)); unrefdResources.remove(resVar.sym); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java index d0ed3abcaaf5b..97f961f09bf48 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java @@ -87,6 +87,7 @@ import com.sun.tools.javac.jvm.Target; import com.sun.tools.javac.main.Option; import com.sun.tools.javac.resources.CompilerProperties.Errors; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; @@ -1275,7 +1276,7 @@ private void setupAllModules() { for (ModuleSymbol msym : limitMods) { if (!observable.contains(msym)) { log.warning( - Warnings.ModuleForOptionNotFound(Option.LIMIT_MODULES, msym)); + LintWarnings.ModuleForOptionNotFound(Option.LIMIT_MODULES, msym)); } } } @@ -1380,7 +1381,7 @@ private void setupAllModules() { .collect(Collectors.joining(",")); if (!incubatingModules.isEmpty()) { - log.warning(Warnings.IncubatingModules(incubatingModules)); + log.warning(LintWarnings.IncubatingModules(incubatingModules)); } } @@ -1731,7 +1732,7 @@ private boolean isKnownModule(ModuleSymbol msym, Set unknownModule if (!unknownModules.contains(msym)) { if (lintOptions) { log.warning( - Warnings.ModuleForOptionNotFound(Option.ADD_EXPORTS, msym)); + LintWarnings.ModuleForOptionNotFound(Option.ADD_EXPORTS, msym)); } unknownModules.add(msym); } @@ -1769,7 +1770,7 @@ private void initAddReads() { ModuleSymbol msym = syms.enterModule(names.fromString(sourceName)); if (!allModules.contains(msym)) { if (lintOptions) { - log.warning(Warnings.ModuleForOptionNotFound(Option.ADD_READS, msym)); + log.warning(LintWarnings.ModuleForOptionNotFound(Option.ADD_READS, msym)); } continue; } @@ -1789,7 +1790,7 @@ private void initAddReads() { targetModule = syms.enterModule(names.fromString(targetName)); if (!allModules.contains(targetModule)) { if (lintOptions) { - log.warning(Warnings.ModuleForOptionNotFound(Option.ADD_READS, targetModule)); + log.warning(LintWarnings.ModuleForOptionNotFound(Option.ADD_READS, targetModule)); } continue; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java index 35b0e89c8a4dd..67486dbe4bf3e 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java @@ -51,6 +51,7 @@ import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Types; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.*; @@ -421,12 +422,12 @@ private boolean currentClassIsExternallyExtendable() { previous = warning; // Emit warnings showing the entire stack trace - JCDiagnostic.Warning key = Warnings.PossibleThisEscape; + JCDiagnostic.Warning key = LintWarnings.PossibleThisEscape; int remain = warning.length; do { DiagnosticPosition pos = warning[--remain]; log.warning(pos, key); - key = Warnings.PossibleThisEscapeLocation; + key = LintWarnings.PossibleThisEscapeLocation; } while (remain > 0); } warningList.clear(); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java index 9b2d4e9f2a35b..f2f8eb0f0df42 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java @@ -57,6 +57,7 @@ import com.sun.tools.javac.main.OptionHelper; import com.sun.tools.javac.main.OptionHelper.GrumpyHelper; import com.sun.tools.javac.resources.CompilerProperties.Errors; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.DefinedBy; @@ -524,6 +525,6 @@ synchronized void newOutputToPath(Path path) throws IOException { // Check whether we've already opened this file for output if (!outputFilesWritten.add(realPath)) - log.warning(Warnings.OutputFileClash(path)); + log.warning(LintWarnings.OutputFileClash(path)); // @@@: shouldn't we check for suppression? } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java index 98bc53b57fa2d..3a6ed52cc79e7 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java @@ -77,6 +77,8 @@ import javax.tools.StandardJavaFileManager.PathFactory; import javax.tools.StandardLocation; +import com.sun.tools.javac.code.Lint; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import jdk.internal.jmod.JmodFile; import com.sun.tools.javac.main.Option; @@ -222,7 +224,7 @@ private Iterable getPathEntries(String searchPath, Path emptyPathDefault) entries.add(getPath(s)); } catch (IllegalArgumentException e) { if (warn) { - log.warning(Warnings.InvalidPath(s)); + log.warning(LintWarnings.InvalidPath(s)); } } } @@ -318,7 +320,7 @@ private void addDirectory(Path dir, boolean warn) { if (!Files.isDirectory(dir)) { if (warn) { log.warning( - Warnings.DirPathElementNotFound(dir)); + LintWarnings.DirPathElementNotFound(dir)); } return; } @@ -364,7 +366,7 @@ public void addFile(Path file, boolean warn) { /* No such file or directory exists */ if (warn) { log.warning( - Warnings.PathElementNotFound(file)); + LintWarnings.PathElementNotFound(file)); } super.add(file); return; @@ -387,13 +389,13 @@ public void addFile(Path file, boolean warn) { FileSystems.newFileSystem(file, (ClassLoader)null).close(); if (warn) { log.warning( - Warnings.UnexpectedArchiveFile(file)); + LintWarnings.UnexpectedArchiveFile(file)); } } catch (IOException | ProviderNotFoundException e) { // FIXME: include e.getLocalizedMessage in warning if (warn) { log.warning( - Warnings.InvalidArchiveFile(file)); + LintWarnings.InvalidArchiveFile(file)); } return; } @@ -1658,8 +1660,8 @@ void add(Map> map, Path prefix, Path suffix) { if (!Files.isDirectory(prefix)) { if (warn) { Warning key = Files.exists(prefix) - ? Warnings.DirPathElementNotDirectory(prefix) - : Warnings.DirPathElementNotFound(prefix); + ? LintWarnings.DirPathElementNotDirectory(prefix) + : LintWarnings.DirPathElementNotFound(prefix); log.warning(key); } return; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java index ca620219ce015..7147e97289853 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java @@ -64,6 +64,7 @@ import com.sun.tools.javac.main.Option; import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Fragments; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.ByteBuffer.UnderflowException; @@ -856,7 +857,7 @@ protected boolean accepts(AttributeKind kind) { JavaFileObject prev = log.useSource(currentClassFile); try { log.warning((DiagnosticPosition) null, - Warnings.FutureAttr(name, version.major, version.minor, majorVersion, minorVersion)); + LintWarnings.FutureAttr(name, version.major, version.minor, majorVersion, minorVersion)); } finally { log.useSource(prev); } @@ -1610,7 +1611,7 @@ void readParameterAnnotations(Symbol meth) { //the RuntimeVisibleParameterAnnotations and RuntimeInvisibleParameterAnnotations //provide annotations for a different number of parameters, ignore: if (lintClassfile) { - log.warning(Warnings.RuntimeVisibleInvisibleParamAnnotationsMismatch(currentClassFile)); + log.warning(LintWarnings.RuntimeVisibleInvisibleParamAnnotationsMismatch(currentClassFile)); } for (int pnum = 0; pnum < numParameters; pnum++) { readAnnotations(); @@ -2078,9 +2079,9 @@ MethodSymbol findAccessMethod(Type container, Name name) { try { if (lintClassfile) { if (failure == null) { - log.warning(Warnings.AnnotationMethodNotFound(container, name)); + log.warning(LintWarnings.AnnotationMethodNotFound(container, name)); } else { - log.warning(Warnings.AnnotationMethodNotFoundReason(container, + log.warning(LintWarnings.AnnotationMethodNotFoundReason(container, name, failure.getDetailValue()));//diagnostic, if present } @@ -2960,7 +2961,7 @@ void adjustParameterAnnotations(MethodSymbol sym, Type methodDescriptor, private void dropParameterAnnotations() { parameterAnnotations = null; if (lintClassfile) { - log.warning(Warnings.RuntimeInvisibleParameterAnnotations(currentClassFile)); + log.warning(LintWarnings.RuntimeInvisibleParameterAnnotations(currentClassFile)); } } /** diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java index de81ddf58577e..1e8b85eb1437f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java @@ -63,6 +63,7 @@ import com.sun.tools.javac.platform.PlatformUtils; import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Fragments; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.JCDiagnostic; @@ -497,7 +498,7 @@ public boolean validate() { if (lintPaths) { Path outDirParent = outDir.getParent(); if (outDirParent != null && Files.exists(outDirParent.resolve("module-info.class"))) { - log.warning(Warnings.OutdirIsInExplodedModule(outDir)); + log.warning(LintWarnings.OutdirIsInExplodedModule(outDir)); } } } @@ -571,10 +572,10 @@ public boolean validate() { if (fm instanceof BaseFileManager baseFileManager) { if (source.compareTo(Source.JDK8) <= 0) { if (baseFileManager.isDefaultBootClassPath()) - log.warning(Warnings.SourceNoBootclasspath(source.name, releaseNote(source, targetString))); + log.warning(LintWarnings.SourceNoBootclasspath(source.name, releaseNote(source, targetString))); } else { if (baseFileManager.isDefaultSystemModulesPath()) - log.warning(Warnings.SourceNoSystemModulesPath(source.name, releaseNote(source, targetString))); + log.warning(LintWarnings.SourceNoSystemModulesPath(source.name, releaseNote(source, targetString))); } } } @@ -584,14 +585,14 @@ public boolean validate() { if (source.compareTo(Source.MIN) < 0) { log.error(Errors.OptionRemovedSource(source.name, Source.MIN.name)); } else if (source == Source.MIN && lintOptions) { - log.warning(Warnings.OptionObsoleteSource(source.name)); + log.warning(LintWarnings.OptionObsoleteSource(source.name)); obsoleteOptionFound = true; } if (target.compareTo(Target.MIN) < 0) { log.error(Errors.OptionRemovedTarget(target, Target.MIN)); } else if (target == Target.MIN && lintOptions) { - log.warning(Warnings.OptionObsoleteTarget(target)); + log.warning(LintWarnings.OptionObsoleteTarget(target)); obsoleteOptionFound = true; } @@ -625,7 +626,7 @@ public boolean validate() { } if (obsoleteOptionFound && lintOptions) { - log.warning(Warnings.OptionObsoleteSuppression); + log.warning(LintWarnings.OptionObsoleteSuppression); } SourceVersion sv = Source.toSourceVersion(source); @@ -636,7 +637,7 @@ public boolean validate() { validateDefaultModuleForCreatedFiles(sv); if (lintOptions && options.isSet(Option.ADD_OPENS)) { - log.warning(Warnings.AddopensIgnored); + log.warning(LintWarnings.AddopensIgnored); } return !errors && (log.nerrors == 0); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java index a09d82aa70e1c..b25ca99eb88f7 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java @@ -33,6 +33,7 @@ import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle; import com.sun.tools.javac.resources.CompilerProperties.Errors; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.util.*; @@ -1073,11 +1074,11 @@ public Token readToken() { TextBlockSupport.checkWhitespace(string); if (checks.contains(TextBlockSupport.WhitespaceChecks.INCONSISTENT)) { lexWarning(pos, - Warnings.InconsistentWhiteSpaceIndentation); + LintWarnings.InconsistentWhiteSpaceIndentation); } if (checks.contains(TextBlockSupport.WhitespaceChecks.TRAILING)) { lexWarning(pos, - Warnings.TrailingWhiteSpaceWillBeRemoved); + LintWarnings.TrailingWhiteSpaceWillBeRemoved); } } // Remove incidental indentation. diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java index 43b99f52e57bf..1413c51191378 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -42,6 +42,7 @@ import com.sun.tools.javac.parser.Tokens.*; import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Fragments; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.*; @@ -670,7 +671,7 @@ void reportDanglingDocComment(Comment c) { if (lint.isEnabled(Lint.LintCategory.DANGLING_DOC_COMMENTS) && !shebang(c, pos)) { log.warning( - pos, Warnings.DanglingDocComment); + pos, LintWarnings.DanglingDocComment); } }); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java index 1c3f8ba96f882..3f30bee31f935 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java @@ -57,6 +57,7 @@ import com.sun.tools.javac.code.Symtab; import com.sun.tools.javac.comp.Modules; import com.sun.tools.javac.model.JavacElements; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.DefinedBy.Api; @@ -492,7 +493,7 @@ private JavaFileObject createSourceOrClassFile(ModuleSymbol mod, boolean isSourc String base = name.substring(periodIndex); String extn = (isSourceFile ? ".java" : ".class"); if (base.equals(extn)) - log.warning(Warnings.ProcSuspiciousClassName(name, extn)); + log.warning(LintWarnings.ProcSuspiciousClassName(name, extn)); } } checkNameAndExistence(mod, name, isSourceFile); @@ -708,7 +709,7 @@ private void checkName(String name) throws FilerException { private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException { if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) { if (lint) - log.warning(Warnings.ProcIllegalFileName(name)); + log.warning(LintWarnings.ProcIllegalFileName(name)); throw new FilerException("Illegal name " + name); } } @@ -737,11 +738,11 @@ private void checkNameAndExistence(ModuleSymbol mod, String typename, boolean al containedInInitialInputs(typename); if (alreadySeen) { if (lint) - log.warning(Warnings.ProcTypeRecreate(typename)); + log.warning(LintWarnings.ProcTypeRecreate(typename)); throw new FilerException("Attempt to recreate a file for type " + typename); } if (lint && existing != null) { - log.warning(Warnings.ProcTypeAlreadyExists(typename)); + log.warning(LintWarnings.ProcTypeAlreadyExists(typename)); } if (!mod.isUnnamed() && !typename.contains(".")) { throw new FilerException("Attempt to create a type in unnamed package of a named module: " + typename); @@ -771,7 +772,7 @@ private boolean containedInInitialInputs(String typename) { private void checkFileReopening(FileObject fileObject, boolean forWriting) throws FilerException { if (isInFileObjectHistory(fileObject, forWriting)) { if (lint) - log.warning(Warnings.ProcFileReopening(fileObject.getName())); + log.warning(LintWarnings.ProcFileReopening(fileObject.getName())); throw new FilerException("Attempt to reopen a file for path " + fileObject.getName()); } if (forWriting) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java index 1870d487c5900..569e1f64a514a 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java @@ -70,6 +70,7 @@ import com.sun.tools.javac.platform.PlatformDescription; import com.sun.tools.javac.platform.PlatformDescription.PluginInfo; import com.sun.tools.javac.resources.CompilerProperties.Errors; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.*; @@ -714,7 +715,7 @@ static class ProcessorState { add(importStringToPattern(allowModules, annotationPattern, processor, log, lint)); if (lint && !patternAdded) { - log.warning(Warnings.ProcDuplicateSupportedAnnotation(annotationPattern, + log.warning(LintWarnings.ProcDuplicateSupportedAnnotation(annotationPattern, p.getClass().getName())); } } @@ -728,7 +729,7 @@ static class ProcessorState { if (lint && supportedAnnotationPatterns.contains(MatchingUtils.validImportStringToPattern("*")) && supportedAnnotationPatterns.size() > 1) { - log.warning(Warnings.ProcRedundantTypesWithWildcard(p.getClass().getName())); + log.warning(LintWarnings.ProcRedundantTypesWithWildcard(p.getClass().getName())); } supportedOptionNames = new LinkedHashSet<>(); @@ -736,7 +737,7 @@ static class ProcessorState { if (checkOptionName(optionName, log)) { boolean optionAdded = supportedOptionNames.add(optionName); if (lint && !optionAdded) { - log.warning(Warnings.ProcDuplicateOptionName(optionName, + log.warning(LintWarnings.ProcDuplicateOptionName(optionName, p.getClass().getName())); } } @@ -957,7 +958,7 @@ private void discoverAndRunProcs(Set annotationsPresent, // Remove annotations processed by javac unmatchedAnnotations.keySet().removeAll(platformAnnotations); if (unmatchedAnnotations.size() > 0) { - log.warning(Warnings.ProcAnnotationsWithoutProcessors(unmatchedAnnotations.keySet())); + log.warning(LintWarnings.ProcAnnotationsWithoutProcessors(unmatchedAnnotations.keySet())); } } @@ -1780,7 +1781,7 @@ private static Pattern importStringToPattern(boolean allowModules, String s, Pro private static Pattern warnAndNoMatches(String s, Processor p, Log log, boolean lint) { if (lint) { - log.warning(Warnings.ProcMalformedSupportedString(s, p.getClass().getName())); + log.warning(LintWarnings.ProcMalformedSupportedString(s, p.getClass().getName())); } return noMatches; // won't match any valid identifier } 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 8efce29d474a4..866bc30f3d569 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 @@ -1930,6 +1930,7 @@ compiler.warn.has.been.deprecated.for.removal=\ {0} in {1} has been deprecated and marked for removal # 0: symbol +# lint: preview compiler.warn.is.preview=\ {0} is a preview API and may be removed in a future release. @@ -1939,6 +1940,7 @@ compiler.err.is.preview=\ (use --enable-preview to enable preview APIs) # 0: symbol +# lint: preview compiler.warn.is.preview.reflective=\ {0} is a reflective preview API and may be removed in a future release. @@ -3149,11 +3151,13 @@ compiler.err.override.incompatible.ret=\ return type {1} is not compatible with {2} # 0: message segment, 1: type, 2: type +# lint: unchecked compiler.warn.override.unchecked.ret=\ {0}\n\ return type requires unchecked conversion from {1} to {2} # 0: message segment, 1: type +# lint: unchecked compiler.warn.override.unchecked.thrown=\ {0}\n\ overridden method does not throw {1} @@ -4214,6 +4218,7 @@ compiler.err.incorrect.number.of.nested.patterns=\ found: {1} # 0: kind name, 1: symbol +# lint: preview compiler.warn.declared.using.preview=\ {0} {1} is declared using a preview feature, which may be removed in a future release. diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java index a8de786e1afbc..3e07751009b4d 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java @@ -304,8 +304,8 @@ public JCDiagnostic create( //where DiagnosticInfo normalize(DiagnosticInfo diagnosticInfo) { //replace all nested FragmentKey with full-blown JCDiagnostic objects - LintCategory category = diagnosticInfo instanceof Warning warning ? - warning.category : null; + LintCategory category = diagnosticInfo instanceof LintWarning lintWarning ? + lintWarning.category : null; return DiagnosticInfo.of(diagnosticInfo.type, category, diagnosticInfo.prefix, diagnosticInfo.code, Stream.of(diagnosticInfo.args).map(o -> { return (o instanceof Fragment frag) ? @@ -542,7 +542,9 @@ public static DiagnosticInfo of(DiagnosticType type, LintCategory lc, String pre case ERROR: return new Error(prefix, code, args); case WARNING: - return new Warning(lc, prefix, code, args); + return lc == null ? + new Warning(prefix, code, args) : + new LintWarning(lc, prefix, code, args); case NOTE: return new Note(prefix, code, args); case FRAGMENT: @@ -584,17 +586,26 @@ public Error(String prefix, String key, Object... args) { /** * Class representing warning diagnostic keys. */ - public static final class Warning extends DiagnosticInfo { - final LintCategory category; - + public static sealed class Warning extends DiagnosticInfo { public Warning(String prefix, String key, Object... args) { - this(null, prefix, key, args); + super(DiagnosticType.WARNING, prefix, key, args); } + } - public Warning(LintCategory category, String prefix, String key, Object... args) { - super(DiagnosticType.WARNING, prefix, key, args); + /** + * Class representing warning diagnostic keys. + */ + public static final class LintWarning extends Warning { + final LintCategory category; + + public LintWarning(LintCategory category, String prefix, String key, Object... args) { + super(prefix, key, args); this.category = category; } + + public LintCategory getLintCategory() { + return category; + } } /** @@ -697,8 +708,8 @@ public boolean hasLintCategory() { * Get the associated lint category, or null if none. */ public LintCategory getLintCategory() { - return diagnosticInfo instanceof Warning warning ? - warning.category : null; + return diagnosticInfo instanceof LintWarning lintWarning ? + lintWarning.category : null; } /** diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java index 463819afa698d..636563621a4a6 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java @@ -33,6 +33,7 @@ import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.code.Source; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; +import com.sun.tools.javac.util.JCDiagnostic.LintWarning; import com.sun.tools.javac.util.JCDiagnostic.Note; import com.sun.tools.javac.util.JCDiagnostic.Warning; @@ -110,21 +111,25 @@ private enum DeferredDiagnosticKind { * True if mandatory warnings and notes are being enforced. * @param prefix A common prefix for the set of message keys for * the messages that may be generated. + * @param lc An associated lint category for the warnings, or null if none. */ public MandatoryWarningHandler(Log log, Source source, boolean verbose, - boolean enforceMandatory, String prefix) { + boolean enforceMandatory, String prefix, + LintCategory lc) { this.log = log; this.source = source; this.verbose = verbose; this.prefix = prefix; this.enforceMandatory = enforceMandatory; + this.lintCategory = lc; } /** * Report a mandatory warning. */ - public void report(DiagnosticPosition pos, Warning warnKey) { + public void report(DiagnosticPosition pos, LintWarning warnKey) { JavaFileObject currentSource = log.currentSourceFile(); + Assert.check(warnKey.getLintCategory() == lintCategory); if (verbose) { if (sourcesWithReportedWarnings == null) @@ -243,6 +248,12 @@ public void reportDeferredDiagnostic() { */ private final boolean enforceMandatory; + /** + * A LintCategory to be included in point-of-use diagnostics to indicate + * how messages might be suppressed (i.e. with @SuppressWarnings). + */ + private final LintCategory lintCategory; + /** * Reports a mandatory warning to the log. If mandatory warnings * are not being enforced, treat this as an ordinary warning. diff --git a/test/langtools/tools/javac/6304921/TestLog.java b/test/langtools/tools/javac/6304921/TestLog.java index 3d88aa6fdfd65..41695554a8800 100644 --- a/test/langtools/tools/javac/6304921/TestLog.java +++ b/test/langtools/tools/javac/6304921/TestLog.java @@ -41,6 +41,7 @@ import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.parser.Parser; import com.sun.tools.javac.parser.ParserFactory; +import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; import com.sun.tools.javac.tree.EndPosTable; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.TreeScanner; @@ -51,7 +52,6 @@ import com.sun.tools.javac.util.JCDiagnostic.Factory; import com.sun.tools.javac.util.Options; import com.sun.tools.javac.resources.CompilerProperties.Errors; -import com.sun.tools.javac.resources.CompilerProperties.Warnings; public class TestLog { @@ -130,10 +130,10 @@ public void visitIf(JCTree.JCIf tree) { log.error(tree.pos(), Errors.NotStmt); log.error(nil, Errors.NotStmt); - log.warning(Warnings.DivZero); - log.warning(tree.pos, Warnings.DivZero); - log.warning(tree.pos(), Warnings.DivZero); - log.warning(nil, Warnings.DivZero); + log.warning(LintWarnings.DivZero); + log.warning(tree.pos, LintWarnings.DivZero); + log.warning(tree.pos(), LintWarnings.DivZero); + log.warning(nil, LintWarnings.DivZero); } private Log log; From 9a657f23da934179b86a66be380804e9ceea09da Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Wed, 4 Dec 2024 18:54:38 +0000 Subject: [PATCH 08/10] Fix regression --- .../share/classes/com/sun/tools/javac/comp/Attr.java | 4 ++-- .../share/classes/com/sun/tools/javac/comp/Check.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index b66e6525dc651..e5a36b50de384 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -4469,9 +4469,9 @@ public void visitSelect(JCFieldAccess tree) { // If the qualified item is not a type and the selected item is static, report // a warning. Make allowance for the class of an array type e.g. Object[].class) if (!sym.owner.isAnonymous()) { - env.info.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType(sym.kind.kindName(), sym.owner)); + chk.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType(sym.kind.kindName(), sym.owner)); } else { - env.info.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType2(sym.kind.kindName())); + chk.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType2(sym.kind.kindName())); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index 8f91dcde16515..fb1b852ca47ce 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -120,7 +120,7 @@ public class Check { // The set of lint options currently in effect. It is initialized // from the context, and then is set/reset as needed by Attr as it // visits all the various parts of the trees during attribution. - private Lint lint; + Lint lint; // The method being analyzed in Attr - it is set/reset as needed by // Attr as it visits new method declarations. From 64883bbd0a5fc0275696e822af3a74fba394ee4b Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Thu, 5 Dec 2024 08:51:00 +0000 Subject: [PATCH 09/10] Add missing lint categories in compiler.properties Simplify some lambda expressions Simplify Lint::logIfEnabled by accepting a log parameter --- .../com/sun/tools/javac/code/Lint.java | 5 +- .../com/sun/tools/javac/comp/Attr.java | 10 +-- .../com/sun/tools/javac/comp/Check.java | 89 +++++++++---------- .../com/sun/tools/javac/comp/Flow.java | 4 +- .../sun/tools/javac/file/BaseFileManager.java | 2 +- .../tools/javac/resources/compiler.properties | 22 +++++ 6 files changed, 72 insertions(+), 60 deletions(-) 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 e46b58b0954ea..c55830849c88a 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 @@ -96,7 +96,6 @@ public Lint suppress(LintCategory... lc) { return l; } - private final Log log; private final AugmentVisitor augmentor; private final EnumSet values; @@ -150,14 +149,12 @@ protected Lint(Context context) { context.put(lintKey, this); augmentor = new AugmentVisitor(context); - log = Log.instance(context); } protected Lint(Lint other) { this.augmentor = other.augmentor; this.values = other.values.clone(); this.suppressedValues = other.suppressedValues.clone(); - this.log = other.log; } @Override @@ -394,7 +391,7 @@ public boolean isSuppressed(LintCategory lc) { /** * Helper method. Log a lint warning if its lint category is enabled. */ - public void logIfEnabled(DiagnosticPosition pos, LintWarning warning) { + public void logIfEnabled(Log log, DiagnosticPosition pos, LintWarning warning) { if (isEnabled(warning.getLintCategory())) { log.warning(pos, warning); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index e5a36b50de384..982d348592f7c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -1940,7 +1940,7 @@ private Symbol enumConstant(JCTree tree, Type enumType) { public void visitSynchronized(JCSynchronized tree) { chk.checkRefType(tree.pos(), attribExpr(tree.lock, env)); if (isValueBased(tree.lock.type)) { - env.info.lint.logIfEnabled(tree.pos(), LintWarnings.AttemptToSynchronizeOnInstanceOfValueBasedClass); + env.info.lint.logIfEnabled(log, tree.pos(), LintWarnings.AttemptToSynchronizeOnInstanceOfValueBasedClass); } attribStat(tree.body, env); result = null; @@ -2047,7 +2047,7 @@ void checkAutoCloseable(DiagnosticPosition pos, Env env, Type resou if (close.kind == MTH && close.overrides(syms.autoCloseableClose, resource.tsym, types, true) && chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes())) { - env.info.lint.logIfEnabled(pos, LintWarnings.TryResourceThrowsInterruptedExc(resource)); + env.info.lint.logIfEnabled(log, pos, LintWarnings.TryResourceThrowsInterruptedExc(resource)); } } } @@ -4442,7 +4442,7 @@ public void visitSelect(JCFieldAccess tree) { sym.kind == MTH && sym.name.equals(names.close) && sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true)) { - env.info.lint.logIfEnabled(tree, LintWarnings.TryExplicitCloseCall); + env.info.lint.logIfEnabled(log, tree, LintWarnings.TryExplicitCloseCall); } // Disallow selecting a type from an expression @@ -4469,9 +4469,9 @@ public void visitSelect(JCFieldAccess tree) { // If the qualified item is not a type and the selected item is static, report // a warning. Make allowance for the class of an array type e.g. Object[].class) if (!sym.owner.isAnonymous()) { - chk.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType(sym.kind.kindName(), sym.owner)); + chk.lint.logIfEnabled(log, tree, LintWarnings.StaticNotQualifiedByType(sym.kind.kindName(), sym.owner)); } else { - chk.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType2(sym.kind.kindName())); + chk.lint.logIfEnabled(log, tree, LintWarnings.StaticNotQualifiedByType2(sym.kind.kindName())); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index fb1b852ca47ce..a1519c040db2d 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -57,7 +57,6 @@ import com.sun.tools.javac.util.JCDiagnostic.Error; import com.sun.tools.javac.util.JCDiagnostic.Fragment; import com.sun.tools.javac.util.JCDiagnostic.LintWarning; -import com.sun.tools.javac.util.JCDiagnostic.Warning; import com.sun.tools.javac.util.List; import com.sun.tools.javac.code.Lint; @@ -286,7 +285,7 @@ public void warnDeclaredUsingPreview(DiagnosticPosition pos, Symbol sym) { * @param msg A Warning describing the problem. */ public void warnRestrictedAPI(DiagnosticPosition pos, Symbol sym) { - lint.logIfEnabled(pos, LintWarnings.RestrictedMethod(sym.enclClass(), sym)); + lint.logIfEnabled(log, pos, LintWarnings.RestrictedMethod(sym.enclClass(), sym)); } /** Warn about unchecked operation. @@ -650,7 +649,7 @@ public void checkRedundantCast(Env env, final JCTypeCast tree) { && !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz)) && !is292targetTypeCast(tree)) { deferredLintHandler.report(_l -> { - lint.logIfEnabled(tree.pos(), LintWarnings.RedundantCast(tree.clazz.type)); + lint.logIfEnabled(log, tree.pos(), LintWarnings.RedundantCast(tree.clazz.type)); }); } } @@ -955,7 +954,7 @@ void checkVarargsMethodDecl(Env env, JCMethodDecl tree) { } } else if (hasTrustMeAnno && varargElemType != null && types.isReifiable(varargElemType)) { - lint.logIfEnabled(tree, LintWarnings.VarargsRedundantTrustmeAnno( + lint.logIfEnabled(log, tree, LintWarnings.VarargsRedundantTrustmeAnno( syms.trustMeType.tsym, diags.fragment(Fragments.VarargsTrustmeOnReifiableVarargs(varargElemType)))); } @@ -1324,9 +1323,7 @@ && checkDisjoint(pos, flags, private void warnOnExplicitStrictfp(DiagnosticPosition pos) { DiagnosticPosition prevLintPos = deferredLintHandler.setPos(pos); try { - deferredLintHandler.report(_ -> { - lint.logIfEnabled(pos, LintWarnings.Strictfp); - }); + deferredLintHandler.report(_ -> lint.logIfEnabled(log, pos, LintWarnings.Strictfp)); } finally { deferredLintHandler.setPos(prevLintPos); } @@ -1545,7 +1542,7 @@ void checkRaw(JCTree tree, Env env) { !TreeInfo.isDiamond(tree) && !withinAnonConstr(env) && tree.type.isRaw()) { - lint.logIfEnabled(tree.pos(), LintWarnings.RawClassUse(tree.type, tree.type.tsym.type)); + lint.logIfEnabled(log, tree.pos(), LintWarnings.RawClassUse(tree.type, tree.type.tsym.type)); } } //where @@ -1869,7 +1866,7 @@ else if (unhandledUnerased.nonEmpty()) { // Optional warning if varargs don't agree if ((((m.flags() ^ other.flags()) & Flags.VARARGS) != 0)) { - lint.logIfEnabled(TreeInfo.diagnosticPositionFor(m, tree), + lint.logIfEnabled(log, TreeInfo.diagnosticPositionFor(m, tree), ((m.flags() & Flags.VARARGS) != 0) ? LintWarnings.OverrideVarargsMissing(varargsOverrides(m, other)) : LintWarnings.OverrideVarargsExtra(varargsOverrides(m, other))); @@ -4093,7 +4090,7 @@ void checkDivZero(final DiagnosticPosition pos, Symbol operator, Type operand) { int opc = ((OperatorSymbol)operator).opcode; if (opc == ByteCodes.idiv || opc == ByteCodes.imod || opc == ByteCodes.ldiv || opc == ByteCodes.lmod) { - deferredLintHandler.report(_ -> lint.logIfEnabled(pos, LintWarnings.DivZero)); + deferredLintHandler.report(_ -> lint.logIfEnabled(log, pos, LintWarnings.DivZero)); } } } @@ -4106,9 +4103,8 @@ void checkDivZero(final DiagnosticPosition pos, Symbol operator, Type operand) { */ void checkLossOfPrecision(final DiagnosticPosition pos, Type found, Type req) { if (found.isNumeric() && req.isNumeric() && !types.isAssignable(found, req)) { - deferredLintHandler.report(_ -> { - lint.logIfEnabled(pos, LintWarnings.PossibleLossOfPrecision(found, req)); - }); + deferredLintHandler.report(_ -> + lint.logIfEnabled(log, pos, LintWarnings.PossibleLossOfPrecision(found, req))); } } @@ -4117,7 +4113,7 @@ void checkLossOfPrecision(final DiagnosticPosition pos, Type found, Type req) { */ void checkEmptyIf(JCIf tree) { if (tree.thenpart.hasTag(SKIP) && tree.elsepart == null) { - lint.logIfEnabled(tree.thenpart.pos(), LintWarnings.EmptyIf); + lint.logIfEnabled(log, tree.thenpart.pos(), LintWarnings.EmptyIf); } } @@ -4264,7 +4260,7 @@ void checkForBadAuxiliaryClassAccess(DiagnosticPosition pos, Env en rs.isAccessible(env, c) && !fileManager.isSameFile(c.sourcefile, env.toplevel.sourcefile)) { - lint.logIfEnabled(pos, + lint.logIfEnabled(log, pos, LintWarnings.AuxiliaryClassAccessedFromOutsideOfItsSourceFile(c, c.sourcefile)); } } @@ -4307,9 +4303,8 @@ void checkDefaultConstructor(ClassSymbol c, DiagnosticPosition pos) { // Warning may be suppressed by // annotations; check again for being // enabled in the deferred context. - deferredLintHandler.report(_ -> { - lint.logIfEnabled(pos, LintWarnings.MissingExplicitCtor(c, pkg, modle)); - }); + deferredLintHandler.report(_ -> + lint.logIfEnabled(log, pos, LintWarnings.MissingExplicitCtor(c, pkg, modle))); } else { return; } @@ -4345,7 +4340,7 @@ public void warn(LintCategory lint) { method.attribute(syms.trustMeType.tsym) != null && isTrustMeAllowedOnMethod(method) && !types.isReifiable(method.type.getParameterTypes().last())) { - Check.this.lint.logIfEnabled(pos(), LintWarnings.VarargsUnsafeUseVarargsParam(method.params.last())); + Check.this.lint.logIfEnabled(log, pos(), LintWarnings.VarargsUnsafeUseVarargsParam(method.params.last())); } break; default: @@ -4643,18 +4638,16 @@ private void checkVisible(DiagnosticPosition pos, Symbol what, PackageSymbol inP void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) { if (msym.kind != MDL) { - deferredLintHandler.report(_ -> { - lint.logIfEnabled(pos, LintWarnings.ModuleNotFound(msym)); - }); + deferredLintHandler.report(_ -> + lint.logIfEnabled(log, pos, LintWarnings.ModuleNotFound(msym))); } } void checkPackageExistsForOpens(final DiagnosticPosition pos, PackageSymbol packge) { if (packge.members().isEmpty() && ((packge.flags() & Flags.HAS_RESOURCE) == 0)) { - deferredLintHandler.report(_ -> { - lint.logIfEnabled(pos, LintWarnings.PackageEmptyOrNotFound(packge)); - }); + deferredLintHandler.report(_ -> + lint.logIfEnabled(log, pos, LintWarnings.PackageEmptyOrNotFound(packge))); } } @@ -4664,7 +4657,7 @@ void checkModuleRequires(final DiagnosticPosition pos, final RequiresDirective r if (rd.isTransitive() && lint.isEnabled(LintCategory.REQUIRES_TRANSITIVE_AUTOMATIC)) { log.warning(pos, LintWarnings.RequiresTransitiveAutomatic); } else { - lint.logIfEnabled(pos, LintWarnings.RequiresAutomatic); + lint.logIfEnabled(log, pos, LintWarnings.RequiresAutomatic); } }); } @@ -4962,7 +4955,7 @@ public Void visitTypeAsClass(TypeElement e, } if (svuidSym == null) { - log.warning(p.pos(), Warnings.MissingSVUID(c)); + log.warning(p.pos(), LintWarnings.MissingSVUID(c)); } // Check for serialPersistentFields to gate checks for @@ -4991,7 +4984,7 @@ public Void visitTypeAsClass(TypeElement e, // component type is not. log.warning( TreeInfo.diagnosticPositionFor(enclosed, tree), - Warnings.NonSerializableInstanceField); + LintWarnings.NonSerializableInstanceField); } else if (varType.hasTag(ARRAY)) { ArrayType arrayType = (ArrayType)varType; Type elementType = arrayType.elemtype; @@ -5002,7 +4995,7 @@ public Void visitTypeAsClass(TypeElement e, if (!canBeSerialized(elementType)) { log.warning( TreeInfo.diagnosticPositionFor(enclosed, tree), - Warnings.NonSerializableInstanceFieldArray(elementType)); + LintWarnings.NonSerializableInstanceFieldArray(elementType)); } } } @@ -5086,7 +5079,7 @@ private void checkCtorAccess(JCClassDecl tree, ClassSymbol c) { } } log.warning(tree.pos(), - Warnings.ExternalizableMissingPublicNoArgCtor); + LintWarnings.ExternalizableMissingPublicNoArgCtor); } else { // Approximate access to the no-arg constructor up in // the superclass chain by checking that the @@ -5114,7 +5107,7 @@ private void checkCtorAccess(JCClassDecl tree, ClassSymbol c) { (supertype.getNestingKind() == NestingKind.MEMBER && ((supertype.flags() & STATIC) == 0))) log.warning(tree.pos(), - Warnings.SerializableMissingAccessNoArgCtor(supertype.getQualifiedName())); + LintWarnings.SerializableMissingAccessNoArgCtor(supertype.getQualifiedName())); } } } @@ -5134,20 +5127,20 @@ private void checkSerialVersionUID(JCClassDecl tree, Element e, VarSymbol svuid) (STATIC | FINAL)) { log.warning( TreeInfo.diagnosticPositionFor(svuid, tree), - Warnings.ImproperSVUID((Symbol)e)); + LintWarnings.ImproperSVUID((Symbol)e)); } // check svuid has type long if (!svuid.type.hasTag(LONG)) { log.warning( TreeInfo.diagnosticPositionFor(svuid, tree), - Warnings.LongSVUID((Symbol)e)); + LintWarnings.LongSVUID((Symbol)e)); } if (svuid.getConstValue() == null) log.warning( TreeInfo.diagnosticPositionFor(svuid, tree), - Warnings.ConstantSVUID((Symbol)e)); + LintWarnings.ConstantSVUID((Symbol)e)); } private void checkSerialPersistentFields(JCClassDecl tree, Element e, VarSymbol spf) { @@ -5156,19 +5149,19 @@ private void checkSerialPersistentFields(JCClassDecl tree, Element e, VarSymbol (PRIVATE | STATIC | FINAL)) { log.warning( TreeInfo.diagnosticPositionFor(spf, tree), - Warnings.ImproperSPF); + LintWarnings.ImproperSPF); } if (!types.isSameType(spf.type, OSF_TYPE)) { log.warning( TreeInfo.diagnosticPositionFor(spf, tree), - Warnings.OSFArraySPF); + LintWarnings.OSFArraySPF); } if (isExternalizable((Type)(e.asType()))) { log.warning( TreeInfo.diagnosticPositionFor(spf, tree), - Warnings.IneffectualSerialFieldExternalizable); + LintWarnings.IneffectualSerialFieldExternalizable); } // Warn if serialPersistentFields is initialized to a @@ -5179,7 +5172,7 @@ private void checkSerialPersistentFields(JCClassDecl tree, Element e, VarSymbol JCExpression initExpr = variableDef.init; if (initExpr != null && TreeInfo.isNull(initExpr)) { log.warning(initExpr.pos(), - Warnings.SPFNullInit); + LintWarnings.SPFNullInit); } } } @@ -5259,7 +5252,7 @@ private void checkExternMethodRecord(JCClassDecl tree, Element e, MethodSymbol m if (isExtern && isExternMethod(tree, e, method, argType)) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.IneffectualExternalizableMethodRecord(method.getSimpleName().toString())); + LintWarnings.IneffectualExternalizableMethodRecord(method.getSimpleName().toString())); } } @@ -5299,7 +5292,7 @@ public Void visitTypeAsEnum(TypeElement e, if (serialFieldNames.contains(name)) { log.warning( TreeInfo.diagnosticPositionFor(field, tree), - Warnings.IneffectualSerialFieldEnum(name)); + LintWarnings.IneffectualSerialFieldEnum(name)); } } @@ -5308,7 +5301,7 @@ public Void visitTypeAsEnum(TypeElement e, if (serialMethodNames.contains(name)) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.IneffectualSerialMethodEnum(name)); + LintWarnings.IneffectualSerialMethodEnum(name)); } if (isExtern) { @@ -5348,7 +5341,7 @@ private void checkExternMethodEnum(JCClassDecl tree, Element e, MethodSymbol met if (isExternMethod(tree, e, method, argType)) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.IneffectualExternMethodEnum(method.getSimpleName().toString())); + LintWarnings.IneffectualExternMethodEnum(method.getSimpleName().toString())); } } @@ -5380,7 +5373,7 @@ public Void visitTypeAsInterface(TypeElement e, case "serialPersistentFields" -> { log.warning( TreeInfo.diagnosticPositionFor(field, tree), - Warnings.IneffectualSerialFieldInterface); + LintWarnings.IneffectualSerialFieldInterface); } case "serialVersionUID" -> { @@ -5420,7 +5413,7 @@ private void checkPrivateMethod(JCClassDecl tree, if ((method.flags() & PRIVATE) == 0) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.NonPrivateMethodWeakerAccess); + LintWarnings.NonPrivateMethodWeakerAccess); } } @@ -5430,7 +5423,7 @@ private void checkDefaultIneffective(JCClassDecl tree, if ((method.flags() & DEFAULT) == DEFAULT) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.DefaultIneffective); + LintWarnings.DefaultIneffective); } } @@ -5477,7 +5470,7 @@ public Void visitTypeAsRecord(TypeElement e, case "serialPersistentFields" -> { log.warning( TreeInfo.diagnosticPositionFor(field, tree), - Warnings.IneffectualSerialFieldRecord); + LintWarnings.IneffectualSerialFieldRecord); } case "serialVersionUID" -> { @@ -5501,7 +5494,7 @@ public Void visitTypeAsRecord(TypeElement e, if (serialMethodNames.contains(name)) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.IneffectualSerialMethodRecord(name)); + LintWarnings.IneffectualSerialMethodRecord(name)); } }} }}}); @@ -5586,7 +5579,7 @@ private void checkExternalizable(JCClassDecl tree, Element enclosing, MethodSymb if (isExternalizable((Type)enclosing.asType())) { log.warning( TreeInfo.diagnosticPositionFor(method, tree), - Warnings.IneffectualSerialMethodExternalizable(method.getSimpleName())); + LintWarnings.IneffectualSerialMethodExternalizable(method.getSimpleName())); } return; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java index abcca6fe3aea2..e167b81272b70 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java @@ -725,7 +725,7 @@ public void visitSwitch(JCSwitch tree) { // Warn about fall-through if lint switch fallthrough enabled. if (alive == Liveness.ALIVE && c.stats.nonEmpty() && l.tail.nonEmpty()) - lint.logIfEnabled(l.tail.head.pos(), + lint.logIfEnabled(log, l.tail.head.pos(), LintWarnings.PossibleFallThroughIntoCase); } tree.isExhaustive = tree.hasUnconditionalPattern || @@ -1233,7 +1233,7 @@ public void visitTry(JCTry tree) { scanStat(tree.finalizer); tree.finallyCanCompleteNormally = alive != Liveness.DEAD; if (alive == Liveness.DEAD) { - lint.logIfEnabled(TreeInfo.diagEndPos(tree.finalizer), + lint.logIfEnabled(log, TreeInfo.diagEndPos(tree.finalizer), LintWarnings.FinallyCannotComplete); } else { while (exits.nonEmpty()) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java index f2f8eb0f0df42..646db6a6bf333 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java @@ -525,6 +525,6 @@ synchronized void newOutputToPath(Path path) throws IOException { // Check whether we've already opened this file for output if (!outputFilesWritten.add(realPath)) - log.warning(LintWarnings.OutputFileClash(path)); // @@@: shouldn't we check for suppression? + log.warning(LintWarnings.OutputFileClash(path)); } } 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 866bc30f3d569..ca9c254cf8665 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 @@ -1879,6 +1879,7 @@ compiler.warn.lintOption=\ [{0}]\u0020 # 0: symbol +# lint: serial compiler.warn.constant.SVUID=\ serialVersionUID must be constant in class {0} @@ -1968,12 +1969,15 @@ compiler.warn.illegal.char.for.encoding=\ unmappable character for encoding {0} # 0: symbol +# lint: serial compiler.warn.improper.SVUID=\ serialVersionUID must be declared static final in class {0} +# lint: serial compiler.warn.improper.SPF=\ serialPersistentFields must be declared private static final to be effective +# lint: serial compiler.warn.SPF.null.init=\ serialPersistentFields ineffective if initialized to null.\n\ Initialize to an empty array to indicate no fields @@ -1996,17 +2000,21 @@ compiler.warn.unreachable.catch.1=\ thrown types {0} have already been caught # 0: symbol +# lint: serial compiler.warn.long.SVUID=\ serialVersionUID must be of type long in class {0} +# lint: serial compiler.warn.OSF.array.SPF=\ serialPersistentFields must be of type java.io.ObjectStreamField[] to be effective # 0: symbol +# lint: serial compiler.warn.missing.SVUID=\ serializable class {0} has no definition of serialVersionUID # 0: name +# lint: serial compiler.warn.serializable.missing.access.no.arg.ctor=\ cannot access a no-arg constructor in first non-serializable superclass {0} @@ -2051,53 +2059,67 @@ compiler.warn.serial.method.unexpected.return.type=\ compiler.warn.serial.method.unexpected.exception=\ serialization-related method {0} declared to throw an unexpected type {1} +# lint: serial compiler.warn.ineffectual.serial.field.interface=\ serialPersistentFields is not effective in an interface # 0: string +# lint: serial compiler.warn.ineffectual.serial.field.enum=\ serialization-related field {0} is not effective in an enum class # 0: string +# lint: serial compiler.warn.ineffectual.serial.method.enum=\ serialization-related method {0} is not effective in an enum class # 0: string +# lint: serial compiler.warn.ineffectual.extern.method.enum=\ externalization-related method {0} is not effective in an enum class +# lint: serial compiler.warn.ineffectual.serial.field.record=\ serialPersistentFields is not effective in a record class # 0: string +# lint: serial compiler.warn.ineffectual.serial.method.record=\ serialization-related method {0} is not effective in a record class # 0: string +# lint: serial compiler.warn.ineffectual.externalizable.method.record=\ externalization-related method {0} is not effective in a record class # 0: name +# lint: serial compiler.warn.ineffectual.serial.method.externalizable=\ serialization-related method {0} is not effective in an Externalizable class +# lint: serial compiler.warn.ineffectual.serial.field.externalizable=\ serialPersistentFields is not effective in an Externalizable class +# lint: serial compiler.warn.externalizable.missing.public.no.arg.ctor=\ an Externalizable class needs a public no-arg constructor +# lint: serial compiler.warn.non.serializable.instance.field=\ non-transient instance field of a serializable class declared with a non-serializable type # 0: type +# lint: serial compiler.warn.non.serializable.instance.field.array=\ non-transient instance field of a serializable class declared with an array having a non-serializable base component type {0} +# lint: serial compiler.warn.non.private.method.weaker.access=\ serialization-related method declared non-private in an interface will prevent\n\ classes implementing the interface from declaring the method as private +# lint: serial compiler.warn.default.ineffective=\ serialization-related default method from an interface will not be run by serialization for an implementing class From a3393ca44b14a26bd9741b79252e83babe0f8a17 Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Fri, 6 Dec 2024 10:59:46 +0000 Subject: [PATCH 10/10] Add other missing lint categories --- .../share/classes/com/sun/tools/javac/comp/Check.java | 4 ++-- .../classes/com/sun/tools/javac/resources/compiler.properties | 2 ++ .../share/classes/com/sun/tools/javac/util/JCDiagnostic.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java index a1519c040db2d..f2bf737287e3d 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java @@ -2969,11 +2969,11 @@ void checkAccessFromSerializableElement(final JCTree tree, boolean isLambda) { if (isLambda) { if (belongsToRestrictedPackage(sym)) { log.warning(tree.pos(), - Warnings.AccessToMemberFromSerializableLambda(sym)); + LintWarnings.AccessToMemberFromSerializableLambda(sym)); } } else { log.warning(tree.pos(), - Warnings.AccessToMemberFromSerializableElement(sym)); + LintWarnings.AccessToMemberFromSerializableElement(sym)); } } } 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 ca9c254cf8665..364441cd7edc0 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 @@ -2482,10 +2482,12 @@ compiler.warn.varargs.redundant.trustme.anno=\ Redundant {0} annotation. {1} # 0: symbol +# lint: serial compiler.warn.access.to.member.from.serializable.element=\ access to member {0} from serializable element can be publicly accessible to untrusted code # 0: symbol +# lint: serial compiler.warn.access.to.member.from.serializable.lambda=\ access to member {0} from serializable lambda can be publicly accessible to untrusted code diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java index 3e07751009b4d..92caf7c3f4764 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JCDiagnostic.java @@ -593,7 +593,7 @@ public Warning(String prefix, String key, Object... args) { } /** - * Class representing warning diagnostic keys. + * Class representing lint warning diagnostic keys. */ public static final class LintWarning extends Warning { final LintCategory category;