Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: issue optional warning using '==' for wrapper types #2188

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
be4d139
feat: issue optional warning using '==' for wrapper types
dashorst Mar 20, 2024
5d9a86e
refactor: ComparingWrapper constant -> 1202
dashorst Apr 6, 2024
33b3448
docs: clarify ComparingWrapper detection of boxed types
dashorst Apr 6, 2024
f4e2db9
refactor: use already available severity computation
dashorst Apr 6, 2024
221dcd4
refactor: rename to unlikely equal expression argument type
dashorst Apr 6, 2024
dcd55f0
fix: also rename compiler option and document it
dashorst Apr 6, 2024
0784fef
refactor: UnlikelyEqualExpressionArgumenType -> UnlikelyReferenceComp…
dashorst Apr 8, 2024
389bdfb
refactor: add operator to unlikelyReferenceComparison message
dashorst Apr 8, 2024
b3140c8
fix: CompilerInvocationTests
dashorst Apr 8, 2024
4b3c272
feat: add support for more reference comparison detections
dashorst Apr 8, 2024
384a8ae
fix: UnlikelyReferenceComparison with null should not warn
dashorst Apr 9, 2024
843cc58
test: Ignore unlikely reference comparison in AssignmentTest
dashorst Apr 9, 2024
2eaf0f3
test: Ignore unlikely reference comparison in CastTest
dashorst Apr 9, 2024
ee3fa2d
test: ignore unlikely reference comparison in AutoBoxingTest
dashorst Apr 12, 2024
4372822
test: replace comparingWrapper with unlikelyReferenceComparison in Ba…
dashorst Apr 12, 2024
b07953b
fix: change default of unlikelyReferenceComparison to INFO in Irritan…
dashorst Apr 12, 2024
94fd84b
test: ignore unlikely reference comparison in NegativeLambdaExpressio…
dashorst Apr 12, 2024
89ea49a
test: fix BatchCompilerTest (correctly identified unlikely comparison)
dashorst Apr 12, 2024
b3cf7e2
refactor: unlikelyReferenceComparison -> dubiousReferenceComparison
dashorst May 9, 2024
d4eb747
fix: test runner gave errors on non-normalized paths
dashorst May 9, 2024
df2ef7e
fix: give better test failure messages
dashorst May 9, 2024
d6393d1
Update warning message from Unlikely -> Dubious
dashorst May 9, 2024
3c0d8ac
test: Normalise path differences in assertion
dashorst May 12, 2024
2ec884d
refactor: implement review comments
dashorst May 18, 2024
bf2fec3
clean: remove duplicate entry in CompilerOptions
dashorst May 18, 2024
5d54c68
Merge branch 'master' into dashorst:issue_2176
stephan-herrmann Jun 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Utility class to hold results of processor-based tests.
* All methods are static.
*/
@SuppressWarnings("reference-comparison")
public final class ProcessorTestStatus {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,8 @@ public interface IProblem {
int UnlikelyCollectionMethodArgumentType = 1200;
/** @since 3.13 */
int UnlikelyEqualsArgumentType = 1201;
/** @since 3.38 */
int DubiousReferenceComparison = 1202;

/* Local-Variable Type Inference */
/** @since 3.14 */
Expand Down Expand Up @@ -2621,5 +2623,4 @@ public interface IProblem {
* @noreference preview feature
*/
int DisallowedStatementInPrologue = PreviewRelated + 2023;

}
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,25 @@ public TypeBinding resolveType(BlockScope scope) {
}
}
}

boolean leftTypeIsNumber = new String(leftType.readableName()).equals("java.lang.Number"); //$NON-NLS-1$
boolean rightTypeIsNumber = new String(rightType.readableName()).equals("java.lang.Number"); //$NON-NLS-1$

// both wrapper types or strings. Putting primitives (or calculations) in the mix results
// in unboxing the wrappers to their primitives, so this only warns when both sides are
// wrappers. e.g. (x1 == (x2 + 1)) results in (x2 + 1) becoming a primitive, and an
// unboxing of x1 as well, not necessitating a warning
// when comparing a reference to null the assumption is that the developer is aware of comparing references,
// so the comparison is not unlikely
if((leftType != TypeBinding.NULL && rightType != TypeBinding.NULL) &&
((leftType.isBoxedPrimitiveType() && rightType.isBoxedPrimitiveType()) ||
(!leftType.isPrimitiveType() && (rightType.isBoxedPrimitiveType() || rightTypeIsNumber)) ||
((leftType.isBoxedPrimitiveType() || leftTypeIsNumber) && !rightType.isPrimitiveType()) ||
(leftType.id == rightType.id && (leftType.id == TypeIds.T_JavaLangString || leftTypeIsNumber))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here || leftTypeIsNumber seems unnecessary: the case Number == Number is already covered above. Remove it and test method a8() still triggers the error.

The same even holds for (leftType.isBoxedPrimitiveType() && rightType.isBoxedPrimitiveType()) ||

Detecting "boxed primitive or Number vs. anything non-primitive" covers all wrapper comparisons, doesn't it? 😄

{
scope.problemReporter().dubiousComparison(this, operatorToString(), leftType.readableName(), rightType.readableName());
}

// both base type
if (leftType.isBaseType() && rightType.isBaseType()) {
int leftTypeID = leftType.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@
if (destinationPath == null) {
destinationPath = this.main.destinationPath;
}
if (destinationPath != null && destinationPath != NONE) {

Check warning on line 1305 in org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Potential Programming Problem

LOW: Dubious operand types for '!=': java.lang.String and java.lang.String are references
if (File.separatorChar == '/') {
parameters.put(Logger.OUTPUT, destinationPath);
} else {
Expand Down Expand Up @@ -4468,6 +4468,9 @@
} else if (token.equals("unlikelyEqualsArgumentType")) { //$NON-NLS-1$
setSeverity(CompilerOptions.OPTION_ReportUnlikelyEqualsArgumentType, severity, isEnabling);
return;
} else if (token.equals("dubiousReferenceComparison")) { //$NON-NLS-1$
setSeverity(CompilerOptions.OPTION_ReportDubiousReferenceComparison, severity, isEnabling);
return;
} else if (token.equals("unnecessaryElse")) {//$NON-NLS-1$
setSeverity(CompilerOptions.OPTION_ReportUnnecessaryElse, severity, isEnabling);
return;
Expand Down Expand Up @@ -4649,11 +4652,11 @@
if (this.destinationPath == null) {
currentDestinationPath =
extractDestinationPathFromSourceFile(unitResult);
} else if (this.destinationPath != NONE) {

Check warning on line 4655 in org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Potential Programming Problem

LOW: Dubious operand types for '!=': java.lang.String and java.lang.String are references
currentDestinationPath = this.destinationPath;
generateClasspathStructure = true;
} // else leave currentDestinationPath null
} else if (compilationUnit.destinationPath != NONE) {

Check warning on line 4659 in org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Potential Programming Problem

LOW: Dubious operand types for '!=': java.lang.String and java.lang.String are references
currentDestinationPath = compilationUnit.destinationPath;
generateClasspathStructure = true;
} // else leave currentDestinationPath null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ misc.usage.warn = {1} {2}\n\
\ boxing autoboxing conversion\n\
\ charConcat + char[] in String concat\n\
\ compareIdentical + comparing identical expressions\n\
\ compareWrapped + comparing wrapped primitive expressions\n\
stephan-herrmann marked this conversation as resolved.
Show resolved Hide resolved
\ conditionAssign possible accidental boolean assignment\n\
\ constructorName + method with constructor name\n\
\ deadCode + dead code excluding trivial if (DEBUG) check\n\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public class CompilerOptions {
public static final String OPTION_ReportUnlikelyCollectionMethodArgumentType = "org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType"; //$NON-NLS-1$
public static final String OPTION_ReportUnlikelyCollectionMethodArgumentTypeStrict = "org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict"; //$NON-NLS-1$
public static final String OPTION_ReportUnlikelyEqualsArgumentType = "org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType"; //$NON-NLS-1$
public static final String OPTION_ReportDubiousReferenceComparison = "org.eclipse.jdt.core.compiler.problem.dubiousReferenceComparison"; //$NON-NLS-1$

public static final String OPTION_ReportAPILeak = "org.eclipse.jdt.core.compiler.problem.APILeak"; //$NON-NLS-1$
public static final String OPTION_ReportUnstableAutoModuleName = "org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName"; //$NON-NLS-1$
Expand Down Expand Up @@ -377,6 +378,7 @@ public class CompilerOptions {
// group 3
public static final int InsufficientResourceManagement = IrritantSet.GROUP3 | ASTNode.Bit1;
public static final int IncompatibleOwningContract = IrritantSet.GROUP3 | ASTNode.Bit2;
public static final int DubiousReferenceComparison = IrritantSet.GROUP3 | ASTNode.Bit3;


// Severity level for handlers
Expand Down Expand Up @@ -601,6 +603,7 @@ public class CompilerOptions {
"nls", //$NON-NLS-1$
"null", //$NON-NLS-1$
"rawtypes", //$NON-NLS-1$
"reference-comparison", //$NON-NLS-1$
"removal", //$NON-NLS-1$
"resource", //$NON-NLS-1$
"restriction", //$NON-NLS-1$
Expand Down Expand Up @@ -831,6 +834,8 @@ public static String optionKeyFromIrritant(int irritant) {
return OPTION_ReportUnlikelyCollectionMethodArgumentType;
case UnlikelyEqualsArgumentType:
return OPTION_ReportUnlikelyEqualsArgumentType;
case DubiousReferenceComparison :
return OPTION_ReportDubiousReferenceComparison;
case APILeak:
return OPTION_ReportAPILeak;
case UnstableAutoModuleName:
Expand Down Expand Up @@ -982,6 +987,7 @@ public static String[] warningOptionNames() {
OPTION_ReportDeprecationInDeprecatedCode,
OPTION_ReportDeprecationWhenOverridingDeprecatedMethod,
OPTION_ReportDiscouragedReference,
OPTION_ReportDubiousReferenceComparison,
OPTION_ReportEmptyStatement,
OPTION_ReportEnumIdentifier,
OPTION_ReportFallthroughCase,
Expand Down Expand Up @@ -1191,6 +1197,8 @@ public static String warningTokenFromIrritant(int irritant) {
case UnlikelyEqualsArgumentType:
case UnlikelyCollectionMethodArgumentType:
return "unlikely-arg-type"; //$NON-NLS-1$
case DubiousReferenceComparison:
return "reference-comparison"; //$NON-NLS-1$
case APILeak:
return "exports"; //$NON-NLS-1$
case UnstableAutoModuleName:
Expand Down Expand Up @@ -1263,6 +1271,8 @@ public static IrritantSet warningTokenToIrritants(String warningToken) {
case 'r' :
if ("rawtypes".equals(warningToken)) //$NON-NLS-1$
return IrritantSet.RAW;
if ("reference-comparison".equals(warningToken)) //$NON-NLS-1$
return IrritantSet.UNLIKELY_ARGUMENT_TYPE;
stephan-herrmann marked this conversation as resolved.
Show resolved Hide resolved
if ("resource".equals(warningToken)) //$NON-NLS-1$
return IrritantSet.RESOURCE;
if ("restriction".equals(warningToken)) //$NON-NLS-1$
Expand Down Expand Up @@ -1409,6 +1419,7 @@ public Map<String, String> getMap() {
optionsMap.put(OPTION_EmulateJavacBug8031744, this.emulateJavacBug8031744 ? ENABLED : DISABLED);
optionsMap.put(OPTION_ReportRedundantSuperinterface, getSeverityString(RedundantSuperinterface));
optionsMap.put(OPTION_ReportComparingIdentical, getSeverityString(ComparingIdentical));
optionsMap.put(OPTION_ReportDubiousReferenceComparison, getSeverityString(DubiousReferenceComparison));
optionsMap.put(OPTION_ReportMissingSynchronizedOnInheritedMethod, getSeverityString(MissingSynchronizedModifierInInheritedMethod));
optionsMap.put(OPTION_ReportMissingHashCodeMethod, getSeverityString(ShouldImplementHashcode));
optionsMap.put(OPTION_ReportDeadCode, getSeverityString(DeadCode));
Expand Down Expand Up @@ -1454,6 +1465,7 @@ public Map<String, String> getMap() {
optionsMap.put(OPTION_ReportUnlikelyCollectionMethodArgumentType, getSeverityString(UnlikelyCollectionMethodArgumentType));
optionsMap.put(OPTION_ReportUnlikelyCollectionMethodArgumentTypeStrict, this.reportUnlikelyCollectionMethodArgumentTypeStrict ? ENABLED : DISABLED);
optionsMap.put(OPTION_ReportUnlikelyEqualsArgumentType, getSeverityString(UnlikelyEqualsArgumentType));
optionsMap.put(OPTION_ReportDubiousReferenceComparison, getSeverityString(DubiousReferenceComparison));
optionsMap.put(OPTION_ReportAPILeak, getSeverityString(APILeak));
optionsMap.put(OPTION_ReportUnstableAutoModuleName, getSeverityString(UnstableAutoModuleName));
optionsMap.put(OPTION_EnablePreviews, this.enablePreviewFeatures ? ENABLED : DISABLED);
Expand Down Expand Up @@ -2002,6 +2014,7 @@ && getSeverity(ExplicitlyClosedAutoCloseable) == ProblemSeverities.Ignore) {
this.reportUnlikelyCollectionMethodArgumentTypeStrict = ENABLED.equals(optionValue);
}
if ((optionValue = optionsMap.get(OPTION_ReportUnlikelyEqualsArgumentType)) != null) updateSeverity(UnlikelyEqualsArgumentType, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportDubiousReferenceComparison)) != null) updateSeverity(DubiousReferenceComparison, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportAPILeak)) != null) updateSeverity(APILeak, optionValue);
if ((optionValue = optionsMap.get(OPTION_ReportUnstableAutoModuleName)) != null) updateSeverity(UnstableAutoModuleName, optionValue);
if ((optionValue = optionsMap.get(OPTION_AnnotationBasedNullAnalysis)) != null) {
Expand Down Expand Up @@ -2367,6 +2380,7 @@ public String toString() {
buf.append("\n\t- unlikely argument type for collection methods: ").append(getSeverityString(UnlikelyCollectionMethodArgumentType)); //$NON-NLS-1$
buf.append("\n\t- unlikely argument type for collection methods, strict check against expected type: ").append(this.reportUnlikelyCollectionMethodArgumentTypeStrict ? ENABLED : DISABLED); //$NON-NLS-1$
buf.append("\n\t- unlikely argument types for equals(): ").append(getSeverityString(UnlikelyEqualsArgumentType)); //$NON-NLS-1$
buf.append("\n\t- dubious operand type for equal expression: ").append(getSeverityString(DubiousReferenceComparison)); //$NON-NLS-1$
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

equal expression -> reference comparison

buf.append("\n\t- API leak: ").append(getSeverityString(APILeak)); //$NON-NLS-1$
buf.append("\n\t- unstable auto module name: ").append(getSeverityString(UnstableAutoModuleName)); //$NON-NLS-1$
buf.append("\n\t- SuppressWarnings not fully analysed: ").append(getSeverityString(SuppressWarningsNotAnalysed)); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ public class IrritantSet {
.set(
CompilerOptions.UnlikelyEqualsArgumentType
| CompilerOptions.SuppressWarningsNotAnalysed
| CompilerOptions.AnnotatedTypeArgumentToUnannotated);
| CompilerOptions.AnnotatedTypeArgumentToUnannotated)
// group-3 warnings enabled by default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warnings -> infos

.set(CompilerOptions.DubiousReferenceComparison)
;

COMPILER_DEFAULT_WARNINGS
// group-0 warnings enabled by default
Expand Down Expand Up @@ -140,7 +143,8 @@ public class IrritantSet {
|CompilerOptions.UnstableAutoModuleName
|CompilerOptions.PreviewFeatureUsed)
.set(CompilerOptions.InsufficientResourceManagement
|CompilerOptions.IncompatibleOwningContract);
|CompilerOptions.IncompatibleOwningContract)
;
// default errors IF AnnotationBasedNullAnalysis is enabled:
COMPILER_DEFAULT_ERRORS.set(
CompilerOptions.NullSpecViolation
Expand Down Expand Up @@ -195,7 +199,8 @@ public class IrritantSet {
.set(CompilerOptions.MissingJavadocTags);

UNLIKELY_ARGUMENT_TYPE
.set(CompilerOptions.UnlikelyEqualsArgumentType);
.set(CompilerOptions.UnlikelyEqualsArgumentType)
.set(CompilerOptions.DubiousReferenceComparison);
}
// Internal state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ public static int getIrritant(int problemID) {
return CompilerOptions.UnlikelyCollectionMethodArgumentType;
case IProblem.UnlikelyEqualsArgumentType:
return CompilerOptions.UnlikelyEqualsArgumentType;
case IProblem.DubiousReferenceComparison:
return CompilerOptions.DubiousReferenceComparison;

case IProblem.NonPublicTypeInAPI:
case IProblem.NotExportedTypeInAPI:
Expand Down Expand Up @@ -793,6 +795,7 @@ public static int getProblemCategory(int severity, int problemID) {
case CompilerOptions.NonNullTypeVariableFromLegacyInvocation :
case CompilerOptions.UnlikelyCollectionMethodArgumentType :
case CompilerOptions.UnlikelyEqualsArgumentType:
case CompilerOptions.DubiousReferenceComparison:
case CompilerOptions.APILeak:
case CompilerOptions.UnstableAutoModuleName:
return CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM;
Expand Down Expand Up @@ -11644,6 +11647,15 @@ public void unlikelyArgumentType(Expression argument, MethodBinding method, Type
argument.sourceEnd);
}

public void dubiousComparison(EqualExpression comparison, String operator, char[] leftType, char[] rightType) {
this.handle(
IProblem.DubiousReferenceComparison,
NoArgument,
stephan-herrmann marked this conversation as resolved.
Show resolved Hide resolved
new String[] {operator, new String(leftType), new String(rightType)},
comparison.sourceStart,
comparison.sourceEnd);
}

public void nonPublicTypeInAPI(TypeBinding type, int sourceStart, int sourceEnd) {
handle(IProblem.NonPublicTypeInAPI,
new String[] { new String(type.readableName()) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@
210 = Syntax error on keyword "{0}", no accurate correction available
211 = Comparing identical expressions
212 = Type {0} cannot be safely cast to {1}

220 = Unmatched bracket
221 = The primitive type {0} of {1} does not have a field {2}
222 = Invalid expression as statement
Expand Down Expand Up @@ -908,6 +907,7 @@
# more programming problems:
1200 = Unlikely argument type {0} for {1} on a {2}
1201 = Unlikely argument type for equals(): {0} seems to be unrelated to {2}
1202 = Dubious operand types for '{0}': {1} and {2} are references

### Autoclosable try
1251 = Duplicate resource reference {0}
Expand Down Expand Up @@ -1179,8 +1179,7 @@
# Statements before Super
2022 = Cannot use {0} in a pre-construction context
2023 = {0} statement not allowed in prologue



### ELABORATIONS
## Access restrictions
78592 = The type ''{1}'' is not API (restriction on classpath entry ''{0}'')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
public static boolean isJREVersionEqualTo(String compilerVersion) {
String specVersion = System.getProperty("java.specification.version");
return specVersion != null && Integer.valueOf(specVersion) == Integer.valueOf(compilerVersion);

Check warning on line 47 in org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractBatchCompilerTest.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Potential Programming Problem

LOW: Dubious operand types for '==': java.lang.Integer and java.lang.Integer are references
}
/**
* Abstract normalizer for output comparison. This class merely embodies a
Expand Down Expand Up @@ -665,7 +665,8 @@
"Unexpected error output for invocation with arguments ["
+ extraArguments + "]",
expectedErrOutputString,
errOutputString);
outputDirNormalizer
.normalized(errOutputString));
dashorst marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -855,8 +856,8 @@
expected = expectedClasspathEntries[j++];
if (expected == null) {
assertNull(result.destinationPath);
} else if (expected == Main.NONE &&

Check warning on line 859 in org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractBatchCompilerTest.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Potential Programming Problem

LOW: Dubious operand types for '==': java.lang.String and java.lang.String are references
result.destinationPath != Main.NONE) {

Check warning on line 860 in org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractBatchCompilerTest.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Potential Programming Problem

LOW: Dubious operand types for '!=': java.lang.String and java.lang.String are references
fail("expected 'none' output directory");
} else if (! expected.equals(result.destinationPath)) {
System.out.println("\"" + result.destinationPath + "\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public AssignmentTest(String name) {
protected Map getCompilerOptions() {
Map options = super.getCompilerOptions();
options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE);
options.put(CompilerOptions.OPTION_ReportDubiousReferenceComparison, CompilerOptions.IGNORE);
options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR);
options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR);
options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public AutoBoxingTest(String name) {
protected Map getCompilerOptions() {
Map defaultOptions = super.getCompilerOptions();
defaultOptions.put(CompilerOptions.OPTION_ReportAutoboxing, CompilerOptions.WARNING);
defaultOptions.put(CompilerOptions.OPTION_ReportDubiousReferenceComparison, CompilerOptions.IGNORE);
return defaultOptions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ public void test012b(){
" boxing autoboxing conversion\n" +
" charConcat + char[] in String concat\n" +
" compareIdentical + comparing identical expressions\n" +
" compareWrapped + comparing wrapped primitive expressions\n" +
" conditionAssign possible accidental boolean assignment\n" +
" constructorName + method with constructor name\n" +
" deadCode + dead code excluding trivial if (DEBUG) check\n" +
Expand Down Expand Up @@ -1067,6 +1068,7 @@ public void test013() {
" <option key=\"org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.discouragedReference\" value=\"warning\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.dubiousReferenceComparison\" value=\"info\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.emptyStatement\" value=\"ignore\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.enumIdentifier\" value=\"warning\"/>\n" +
Expand Down Expand Up @@ -11706,47 +11708,52 @@ public void test312_warn_options() {
" ^\n" +
"Null pointer access: The variable o can only be null at this location\n" +
"----------\n" +
"2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 8)\n" +
"2. INFO in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 8)\n" +
" if (o.toString() == \"\"){ return null;}\n" +
" ^^^^^^^^^^^^^^^^^^\n" +
"Dubious operand types for '==': java.lang.String and java.lang.String are references\n" +
"----------\n" +
"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 8)\n" +
" if (o.toString() == \"\"){ return null;}\n" +
" ^\n" +
"Potential null pointer access: The variable o may be null at this location\n" +
"----------\n" +
"3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 8)\n" +
"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 8)\n" +
" if (o.toString() == \"\"){ return null;}\n" +
" ^^^^\n" +
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" +
"----------\n" +
"4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" +
"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" +
" if (o2 == null) {}\n" +
" ^^\n" +
"Null comparison always yields false: The variable o2 is specified as @NonNull\n" +
"----------\n" +
"5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 10)\n" +
"6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 10)\n" +
" goo(null).toString();\n" +
" ^^^^^^^^^\n" +
"Potential null pointer access: The method goo(Object) may return null\n" +
"----------\n" +
"6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 10)\n" +
"7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 10)\n" +
" goo(null).toString();\n" +
" ^^^^\n" +
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" +
"----------\n" +
"7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 13)\n" +
"8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 13)\n" +
" return null;\n" +
" ^^^^\n" +
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" +
"----------\n" +
"8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 19)\n" +
"9. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 19)\n" +
" if (o2 == null){}\n" +
" ^^\n" +
"Null comparison always yields false: The variable o2 is specified as @NonNull\n" +
"----------\n" +
"9. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 20)\n" +
"10. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 20)\n" +
" if (o2 == null){\n" +
" ^^\n" +
"Null comparison always yields false: The variable o2 is specified as @NonNull\n" +
"----------\n" +
"9 problems (9 warnings)\n",
"10 problems (0 errors, 9 warnings, 1 info)\n",
true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected Map getCompilerOptions() {
Map defaultOptions = super.getCompilerOptions();
defaultOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING);
defaultOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
defaultOptions.put(CompilerOptions.OPTION_ReportDubiousReferenceComparison, CompilerOptions.IGNORE);
return defaultOptions;
}
public static Test suite() {
Expand Down
Loading
Loading