8349155: The "log" parameter to Lint.logIfEnabled() is not needed

Reviewed-by: mcimadamore
This commit is contained in:
Archie Cobbs 2025-02-06 01:52:51 +00:00
parent aad6664bb6
commit 89e5e7ab73
8 changed files with 47 additions and 46 deletions

View File

@ -109,6 +109,7 @@ public class Lint {
private final Context context;
private final Options options;
private final Log log;
// These are initialized lazily to avoid dependency loops
private Symtab syms;
@ -125,6 +126,7 @@ public class Lint {
this.context = context;
context.put(lintKey, this);
options = Options.instance(context);
log = Log.instance(context);
}
// Instantiate a non-root ("symbol scoped") instance
@ -132,6 +134,7 @@ public class Lint {
other.initializeRootIfNeeded();
this.context = other.context;
this.options = other.options;
this.log = other.log;
this.syms = other.syms;
this.names = other.names;
this.values = other.values.clone();
@ -434,21 +437,19 @@ public class Lint {
/**
* Helper method. Log a lint warning if its lint category is enabled.
*
* @param log warning destination
* @param warning key for the localized warning message
*/
public void logIfEnabled(Log log, LintWarning warning) {
logIfEnabled(log, null, warning);
public void logIfEnabled(LintWarning warning) {
logIfEnabled(null, warning);
}
/**
* Helper method. Log a lint warning if its lint category is enabled.
*
* @param log warning destination
* @param pos source position at which to report the warning
* @param warning key for the localized warning message
*/
public void logIfEnabled(Log log, DiagnosticPosition pos, LintWarning warning) {
public void logIfEnabled(DiagnosticPosition pos, LintWarning warning) {
if (isEnabled(warning.getLintCategory())) {
log.warning(pos, warning);
}

View File

@ -1949,7 +1949,7 @@ public class Attr extends JCTree.Visitor {
public void visitSynchronized(JCSynchronized tree) {
chk.checkRefType(tree.pos(), attribExpr(tree.lock, env));
if (isValueBased(tree.lock.type)) {
env.info.lint.logIfEnabled(log, tree.pos(), LintWarnings.AttemptToSynchronizeOnInstanceOfValueBasedClass);
env.info.lint.logIfEnabled(tree.pos(), LintWarnings.AttemptToSynchronizeOnInstanceOfValueBasedClass);
}
attribStat(tree.body, env);
result = null;
@ -2056,7 +2056,7 @@ public class Attr extends JCTree.Visitor {
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(log, pos, LintWarnings.TryResourceThrowsInterruptedExc(resource));
env.info.lint.logIfEnabled(pos, LintWarnings.TryResourceThrowsInterruptedExc(resource));
}
}
}
@ -4456,7 +4456,7 @@ public class Attr extends JCTree.Visitor {
sym.kind == MTH &&
sym.name.equals(names.close) &&
sym.overrides(syms.autoCloseableClose, sitesym.type.tsym, types, true)) {
env.info.lint.logIfEnabled(log, tree, LintWarnings.TryExplicitCloseCall);
env.info.lint.logIfEnabled(tree, LintWarnings.TryExplicitCloseCall);
}
// Disallow selecting a type from an expression
@ -4483,9 +4483,9 @@ public class Attr extends JCTree.Visitor {
// 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(log, tree, LintWarnings.StaticNotQualifiedByType(sym.kind.kindName(), sym.owner));
chk.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType(sym.kind.kindName(), sym.owner));
} else {
chk.lint.logIfEnabled(log, tree, LintWarnings.StaticNotQualifiedByType2(sym.kind.kindName()));
chk.lint.logIfEnabled(tree, LintWarnings.StaticNotQualifiedByType2(sym.kind.kindName()));
}
}

View File

@ -285,7 +285,7 @@ public class Check {
* @param msg A Warning describing the problem.
*/
public void warnRestrictedAPI(DiagnosticPosition pos, Symbol sym) {
lint.logIfEnabled(log, pos, LintWarnings.RestrictedMethod(sym.enclClass(), sym));
lint.logIfEnabled(pos, LintWarnings.RestrictedMethod(sym.enclClass(), sym));
}
/** Warn about unchecked operation.
@ -649,7 +649,7 @@ public class Check {
&& !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz))
&& !is292targetTypeCast(tree)) {
deferredLintHandler.report(_l -> {
lint.logIfEnabled(log, tree.pos(), LintWarnings.RedundantCast(tree.clazz.type));
lint.logIfEnabled(tree.pos(), LintWarnings.RedundantCast(tree.clazz.type));
});
}
}
@ -954,7 +954,7 @@ public class Check {
}
} else if (hasTrustMeAnno && varargElemType != null &&
types.isReifiable(varargElemType)) {
lint.logIfEnabled(log, tree, LintWarnings.VarargsRedundantTrustmeAnno(
lint.logIfEnabled(tree, LintWarnings.VarargsRedundantTrustmeAnno(
syms.trustMeType.tsym,
diags.fragment(Fragments.VarargsTrustmeOnReifiableVarargs(varargElemType))));
}
@ -1323,7 +1323,7 @@ public class Check {
private void warnOnExplicitStrictfp(DiagnosticPosition pos) {
DiagnosticPosition prevLintPos = deferredLintHandler.setPos(pos);
try {
deferredLintHandler.report(_ -> lint.logIfEnabled(log, pos, LintWarnings.Strictfp));
deferredLintHandler.report(_ -> lint.logIfEnabled(pos, LintWarnings.Strictfp));
} finally {
deferredLintHandler.setPos(prevLintPos);
}
@ -1542,7 +1542,7 @@ public class Check {
!TreeInfo.isDiamond(tree) &&
!withinAnonConstr(env) &&
tree.type.isRaw()) {
lint.logIfEnabled(log, tree.pos(), LintWarnings.RawClassUse(tree.type, tree.type.tsym.type));
lint.logIfEnabled(tree.pos(), LintWarnings.RawClassUse(tree.type, tree.type.tsym.type));
}
}
//where
@ -1866,7 +1866,7 @@ public class Check {
// Optional warning if varargs don't agree
if ((((m.flags() ^ other.flags()) & Flags.VARARGS) != 0)) {
lint.logIfEnabled(log, TreeInfo.diagnosticPositionFor(m, tree),
lint.logIfEnabled(TreeInfo.diagnosticPositionFor(m, tree),
((m.flags() & Flags.VARARGS) != 0)
? LintWarnings.OverrideVarargsMissing(varargsOverrides(m, other))
: LintWarnings.OverrideVarargsExtra(varargsOverrides(m, other)));
@ -4121,7 +4121,7 @@ public class Check {
int opc = ((OperatorSymbol)operator).opcode;
if (opc == ByteCodes.idiv || opc == ByteCodes.imod
|| opc == ByteCodes.ldiv || opc == ByteCodes.lmod) {
deferredLintHandler.report(_ -> lint.logIfEnabled(log, pos, LintWarnings.DivZero));
deferredLintHandler.report(_ -> lint.logIfEnabled(pos, LintWarnings.DivZero));
}
}
}
@ -4135,7 +4135,7 @@ public class Check {
void checkLossOfPrecision(final DiagnosticPosition pos, Type found, Type req) {
if (found.isNumeric() && req.isNumeric() && !types.isAssignable(found, req)) {
deferredLintHandler.report(_ ->
lint.logIfEnabled(log, pos, LintWarnings.PossibleLossOfPrecision(found, req)));
lint.logIfEnabled(pos, LintWarnings.PossibleLossOfPrecision(found, req)));
}
}
@ -4144,7 +4144,7 @@ public class Check {
*/
void checkEmptyIf(JCIf tree) {
if (tree.thenpart.hasTag(SKIP) && tree.elsepart == null) {
lint.logIfEnabled(log, tree.thenpart.pos(), LintWarnings.EmptyIf);
lint.logIfEnabled(tree.thenpart.pos(), LintWarnings.EmptyIf);
}
}
@ -4291,7 +4291,7 @@ public class Check {
rs.isAccessible(env, c) &&
!fileManager.isSameFile(c.sourcefile, env.toplevel.sourcefile))
{
lint.logIfEnabled(log, pos,
lint.logIfEnabled(pos,
LintWarnings.AuxiliaryClassAccessedFromOutsideOfItsSourceFile(c, c.sourcefile));
}
}
@ -4335,7 +4335,7 @@ public class Check {
// annotations; check again for being
// enabled in the deferred context.
deferredLintHandler.report(_ ->
lint.logIfEnabled(log, pos, LintWarnings.MissingExplicitCtor(c, pkg, modle)));
lint.logIfEnabled(pos, LintWarnings.MissingExplicitCtor(c, pkg, modle)));
} else {
return;
}
@ -4371,7 +4371,7 @@ public class Check {
method.attribute(syms.trustMeType.tsym) != null &&
isTrustMeAllowedOnMethod(method) &&
!types.isReifiable(method.type.getParameterTypes().last())) {
Check.this.lint.logIfEnabled(log, pos(), LintWarnings.VarargsUnsafeUseVarargsParam(method.params.last()));
Check.this.lint.logIfEnabled(pos(), LintWarnings.VarargsUnsafeUseVarargsParam(method.params.last()));
}
break;
default:
@ -4670,7 +4670,7 @@ public class Check {
void checkModuleExists(final DiagnosticPosition pos, ModuleSymbol msym) {
if (msym.kind != MDL) {
deferredLintHandler.report(_ ->
lint.logIfEnabled(log, pos, LintWarnings.ModuleNotFound(msym)));
lint.logIfEnabled(pos, LintWarnings.ModuleNotFound(msym)));
}
}
@ -4678,7 +4678,7 @@ public class Check {
if (packge.members().isEmpty() &&
((packge.flags() & Flags.HAS_RESOURCE) == 0)) {
deferredLintHandler.report(_ ->
lint.logIfEnabled(log, pos, LintWarnings.PackageEmptyOrNotFound(packge)));
lint.logIfEnabled(pos, LintWarnings.PackageEmptyOrNotFound(packge)));
}
}
@ -4688,7 +4688,7 @@ public class Check {
if (rd.isTransitive() && lint.isEnabled(LintCategory.REQUIRES_TRANSITIVE_AUTOMATIC)) {
log.warning(pos, LintWarnings.RequiresTransitiveAutomatic);
} else {
lint.logIfEnabled(log, pos, LintWarnings.RequiresAutomatic);
lint.logIfEnabled(pos, LintWarnings.RequiresAutomatic);
}
});
}

View File

@ -724,7 +724,7 @@ public class Flow {
// Warn about fall-through if lint switch fallthrough enabled.
if (alive == Liveness.ALIVE &&
c.stats.nonEmpty() && l.tail.nonEmpty())
lint.logIfEnabled(log, l.tail.head.pos(),
lint.logIfEnabled(l.tail.head.pos(),
LintWarnings.PossibleFallThroughIntoCase);
}
tree.isExhaustive = tree.hasUnconditionalPattern ||
@ -1232,7 +1232,7 @@ public class Flow {
scanStat(tree.finalizer);
tree.finallyCanCompleteNormally = alive != Liveness.DEAD;
if (alive == Liveness.DEAD) {
lint.logIfEnabled(log, TreeInfo.diagEndPos(tree.finalizer),
lint.logIfEnabled(TreeInfo.diagEndPos(tree.finalizer),
LintWarnings.FinallyCannotComplete);
} else {
while (exits.nonEmpty()) {

View File

@ -225,7 +225,7 @@ public class Locations {
try {
entries.add(getPath(s));
} catch (IllegalArgumentException e) {
lint.logIfEnabled(log, LintWarnings.InvalidPath(s));
lint.logIfEnabled(LintWarnings.InvalidPath(s));
}
}
}
@ -319,7 +319,7 @@ public class Locations {
private void addDirectory(Path dir, boolean warn) {
if (!Files.isDirectory(dir)) {
if (warn) {
lint.logIfEnabled(log, LintWarnings.DirPathElementNotFound(dir));
lint.logIfEnabled(LintWarnings.DirPathElementNotFound(dir));
}
return;
}
@ -364,7 +364,7 @@ public class Locations {
if (!fsInfo.exists(file)) {
/* No such file or directory exists */
if (warn) {
lint.logIfEnabled(log, LintWarnings.PathElementNotFound(file));
lint.logIfEnabled(LintWarnings.PathElementNotFound(file));
}
super.add(file);
return;
@ -386,12 +386,12 @@ public class Locations {
try {
FileSystems.newFileSystem(file, (ClassLoader)null).close();
if (warn) {
lint.logIfEnabled(log, LintWarnings.UnexpectedArchiveFile(file));
lint.logIfEnabled(LintWarnings.UnexpectedArchiveFile(file));
}
} catch (IOException | ProviderNotFoundException e) {
// FIXME: include e.getLocalizedMessage in warning
if (warn) {
lint.logIfEnabled(log, LintWarnings.InvalidArchiveFile(file));
lint.logIfEnabled(LintWarnings.InvalidArchiveFile(file));
}
return;
}
@ -1654,7 +1654,7 @@ public class Locations {
void add(Map<String, List<Path>> map, Path prefix, Path suffix) {
if (!Files.isDirectory(prefix)) {
lint.logIfEnabled(log, Files.exists(prefix) ?
lint.logIfEnabled(Files.exists(prefix) ?
LintWarnings.DirPathElementNotDirectory(prefix) :
LintWarnings.DirPathElementNotFound(prefix));
return;

View File

@ -854,7 +854,7 @@ public class ClassReader {
if (!warnedAttrs.contains(name)) {
JavaFileObject prev = log.useSource(currentClassFile);
try {
lint.logIfEnabled(log,
lint.logIfEnabled(
LintWarnings.FutureAttr(name, version.major, version.minor, majorVersion, minorVersion));
} finally {
log.useSource(prev);
@ -1608,7 +1608,7 @@ public class ClassReader {
} else if (parameterAnnotations.length != numParameters) {
//the RuntimeVisibleParameterAnnotations and RuntimeInvisibleParameterAnnotations
//provide annotations for a different number of parameters, ignore:
lint.logIfEnabled(log, LintWarnings.RuntimeVisibleInvisibleParamAnnotationsMismatch(currentClassFile));
lint.logIfEnabled(LintWarnings.RuntimeVisibleInvisibleParamAnnotationsMismatch(currentClassFile));
for (int pnum = 0; pnum < numParameters; pnum++) {
readAnnotations();
}
@ -2074,9 +2074,9 @@ public class ClassReader {
JavaFileObject prevSource = log.useSource(requestingOwner.classfile);
try {
if (failure == null) {
lint.logIfEnabled(log, LintWarnings.AnnotationMethodNotFound(container, name));
lint.logIfEnabled(LintWarnings.AnnotationMethodNotFound(container, name));
} else {
lint.logIfEnabled(log, LintWarnings.AnnotationMethodNotFoundReason(container,
lint.logIfEnabled(LintWarnings.AnnotationMethodNotFoundReason(container,
name,
failure.getDetailValue()));//diagnostic, if present
}
@ -2954,7 +2954,7 @@ public class ClassReader {
private void dropParameterAnnotations() {
parameterAnnotations = null;
lint.logIfEnabled(log, LintWarnings.RuntimeInvisibleParameterAnnotations(currentClassFile));
lint.logIfEnabled(LintWarnings.RuntimeInvisibleParameterAnnotations(currentClassFile));
}
/**
* Creates the parameter at the position {@code mpIndex} in the parameter list of the owning method.

View File

@ -707,7 +707,7 @@ public class JavacFiler implements Filer, Closeable {
private void checkName(String name, boolean allowUnnamedPackageInfo) throws FilerException {
if (!SourceVersion.isName(name) && !isPackageInfo(name, allowUnnamedPackageInfo)) {
lint.logIfEnabled(log, LintWarnings.ProcIllegalFileName(name));
lint.logIfEnabled(LintWarnings.ProcIllegalFileName(name));
throw new FilerException("Illegal name " + name);
}
}
@ -735,11 +735,11 @@ public class JavacFiler implements Filer, Closeable {
initialClassNames.contains(typename) ||
containedInInitialInputs(typename);
if (alreadySeen) {
lint.logIfEnabled(log, LintWarnings.ProcTypeRecreate(typename));
lint.logIfEnabled(LintWarnings.ProcTypeRecreate(typename));
throw new FilerException("Attempt to recreate a file for type " + typename);
}
if (existing != null) {
lint.logIfEnabled(log, LintWarnings.ProcTypeAlreadyExists(typename));
lint.logIfEnabled(LintWarnings.ProcTypeAlreadyExists(typename));
}
if (!mod.isUnnamed() && !typename.contains(".")) {
throw new FilerException("Attempt to create a type in unnamed package of a named module: " + typename);
@ -768,7 +768,7 @@ public class JavacFiler implements Filer, Closeable {
*/
private void checkFileReopening(FileObject fileObject, boolean forWriting) throws FilerException {
if (isInFileObjectHistory(fileObject, forWriting)) {
lint.logIfEnabled(log, LintWarnings.ProcFileReopening(fileObject.getName()));
lint.logIfEnabled(LintWarnings.ProcFileReopening(fileObject.getName()));
throw new FilerException("Attempt to reopen a file for path " + fileObject.getName());
}
if (forWriting)

View File

@ -649,7 +649,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
add(importStringToPattern(allowModules, annotationPattern,
processor, log, lint));
if (!patternAdded) {
lint.logIfEnabled(log, LintWarnings.ProcDuplicateSupportedAnnotation(annotationPattern,
lint.logIfEnabled(LintWarnings.ProcDuplicateSupportedAnnotation(annotationPattern,
p.getClass().getName()));
}
}
@ -662,7 +662,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
// and "foo.bar.*".
if (supportedAnnotationPatterns.contains(MatchingUtils.validImportStringToPattern("*")) &&
supportedAnnotationPatterns.size() > 1) {
lint.logIfEnabled(log, LintWarnings.ProcRedundantTypesWithWildcard(p.getClass().getName()));
lint.logIfEnabled(LintWarnings.ProcRedundantTypesWithWildcard(p.getClass().getName()));
}
supportedOptionNames = new LinkedHashSet<>();
@ -670,7 +670,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
if (checkOptionName(optionName, log)) {
boolean optionAdded = supportedOptionNames.add(optionName);
if (!optionAdded) {
lint.logIfEnabled(log, LintWarnings.ProcDuplicateOptionName(optionName,
lint.logIfEnabled(LintWarnings.ProcDuplicateOptionName(optionName,
p.getClass().getName()));
}
}
@ -1687,7 +1687,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
}
private static Pattern warnAndNoMatches(String s, Processor p, Log log, Lint lint) {
lint.logIfEnabled(log, LintWarnings.ProcMalformedSupportedString(s, p.getClass().getName()));
lint.logIfEnabled(LintWarnings.ProcMalformedSupportedString(s, p.getClass().getName()));
return noMatches; // won't match any valid identifier
}