You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importjava.util.regex.Pattern;
finalclassDummy {
/** * This is my method. * * @param str This is its parameter. */publicbooleanmyMethod(Stringstr) {
Patternpattern = Pattern.compile(".*");
returnpattern.matcher(str).matches();
}
}
Applying the ConstantPatternCompile check to this code:
--- Dummy.java+++ Dummy.java@@ -7,7 +7,7 @@
* @param str This is its parameter.
*/
- public boolean myMethod(String str) {- Pattern pattern = Pattern.compile(".*");- return pattern.matcher(str).matches();+ static final Pattern PATTERN = Pattern.compile(".*");public boolean myMethod(String str) {++ return PATTERN.matcher(str).matches();
}
}
As can be seen:
The new constant isn't declared private, while it should be.
The new constant is declared between the method and its Javadoc, such that the Javadoc now appears to apply to the constant. (And on a subsequent compilation round InvalidBlockTag will suggest that the @param block tag be removed.)
Although one will likely want to reformat the code anyway, it'd be nice if a newline were inserted after the semicolon.
The text was updated successfully, but these errors were encountered:
Also fix the spacing issue.
Suggestions from #1655
flume hits : http://unknown commit
RELNOTES : Variable created by ConstantPatternCompile should be private. Also fix the spacing issue.
PiperOrigin-RevId: 322705160
Also fix the spacing issue.
Fixes#1655
flume hits : http://unknown commit
RELNOTES : Variable created by ConstantPatternCompile should be private. Also fix the spacing issue.
PiperOrigin-RevId: 322705160
Also fix the spacing issue.
Fixes#1655
flume hits : http://unknown commit
RELNOTES : Variable created by ConstantPatternCompile should be private. Also fix the spacing issue.
PiperOrigin-RevId: 322860215
Consider the following code:
Applying the
ConstantPatternCompile
check to this code:wget \ https://repo1.maven.org/maven2/com/google/errorprone/error_prone_core/2.4.0/error_prone_core-2.4.0-with-dependencies.jar javac \ -XDcompilePolicy=simple \ -processorpath error_prone_core-2.4.0-with-dependencies.jar \ '-Xplugin:ErrorProne -XepPatchChecks:ConstantPatternCompile -XepPatchLocation:/tmp' \ Dummy.java
This yields:
As can be seen:
private
, while it should be.InvalidBlockTag
will suggest that the@param
block tag be removed.)The text was updated successfully, but these errors were encountered: