-
Notifications
You must be signed in to change notification settings - Fork 139
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
dashorst
wants to merge
26
commits into
eclipse-jdt:master
Choose a base branch
from
dashorst:issue_2176
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+341
−23
Open
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 5d9a86e
refactor: ComparingWrapper constant -> 1202
dashorst 33b3448
docs: clarify ComparingWrapper detection of boxed types
dashorst f4e2db9
refactor: use already available severity computation
dashorst 221dcd4
refactor: rename to unlikely equal expression argument type
dashorst dcd55f0
fix: also rename compiler option and document it
dashorst 0784fef
refactor: UnlikelyEqualExpressionArgumenType -> UnlikelyReferenceComp…
dashorst 389bdfb
refactor: add operator to unlikelyReferenceComparison message
dashorst b3140c8
fix: CompilerInvocationTests
dashorst 4b3c272
feat: add support for more reference comparison detections
dashorst 384a8ae
fix: UnlikelyReferenceComparison with null should not warn
dashorst 843cc58
test: Ignore unlikely reference comparison in AssignmentTest
dashorst 2eaf0f3
test: Ignore unlikely reference comparison in CastTest
dashorst ee3fa2d
test: ignore unlikely reference comparison in AutoBoxingTest
dashorst 4372822
test: replace comparingWrapper with unlikelyReferenceComparison in Ba…
dashorst b07953b
fix: change default of unlikelyReferenceComparison to INFO in Irritan…
dashorst 94fd84b
test: ignore unlikely reference comparison in NegativeLambdaExpressio…
dashorst 89ea49a
test: fix BatchCompilerTest (correctly identified unlikely comparison)
dashorst b3cf7e2
refactor: unlikelyReferenceComparison -> dubiousReferenceComparison
dashorst d4eb747
fix: test runner gave errors on non-normalized paths
dashorst df2ef7e
fix: give better test failure messages
dashorst d6393d1
Update warning message from Unlikely -> Dubious
dashorst 3c0d8ac
test: Normalise path differences in assertion
dashorst 2ec884d
refactor: implement review comments
dashorst bf2fec3
clean: remove duplicate entry in CompilerOptions
dashorst 5d54c68
Merge branch 'master' into dashorst:issue_2176
stephan-herrmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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$ | ||
|
@@ -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 | ||
|
@@ -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$ | ||
|
@@ -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: | ||
|
@@ -982,6 +987,7 @@ public static String[] warningOptionNames() { | |
OPTION_ReportDeprecationInDeprecatedCode, | ||
OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, | ||
OPTION_ReportDiscouragedReference, | ||
OPTION_ReportDubiousReferenceComparison, | ||
OPTION_ReportEmptyStatement, | ||
OPTION_ReportEnumIdentifier, | ||
OPTION_ReportFallthroughCase, | ||
|
@@ -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: | ||
|
@@ -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$ | ||
|
@@ -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)); | ||
|
@@ -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); | ||
|
@@ -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) { | ||
|
@@ -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$ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,10 @@ public class IrritantSet { | |
.set( | ||
CompilerOptions.UnlikelyEqualsArgumentType | ||
| CompilerOptions.SuppressWarningsNotAnalysed | ||
| CompilerOptions.AnnotatedTypeArgumentToUnannotated); | ||
| CompilerOptions.AnnotatedTypeArgumentToUnannotated) | ||
// group-3 warnings enabled by default | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.set(CompilerOptions.DubiousReferenceComparison) | ||
; | ||
|
||
COMPILER_DEFAULT_WARNINGS | ||
// group-0 warnings enabled by default | ||
|
@@ -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 | ||
|
@@ -195,7 +199,8 @@ public class IrritantSet { | |
.set(CompilerOptions.MissingJavadocTags); | ||
|
||
UNLIKELY_ARGUMENT_TYPE | ||
.set(CompilerOptions.UnlikelyEqualsArgumentType); | ||
.set(CompilerOptions.UnlikelyEqualsArgumentType) | ||
.set(CompilerOptions.DubiousReferenceComparison); | ||
} | ||
// Internal state | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 caseNumber
==Number
is already covered above. Remove it and test methoda8()
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? 😄