Skip to content

Conversation

JuditKnoll
Copy link
Collaborator

@JuditKnoll JuditKnoll commented Apr 29, 2025

Small cleanup in the ConstructorThrow detector and fix #3417.


Make sure these boxes are checked before submitting your PR -- thank you!

  • Added an entry into CHANGELOG.md if you have changed SpotBugs code

Comment on lines +101 to +106
@Override
public void visit(Method obj) {
hadObjectConstructor = false;
super.visit(obj);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The fix to the issue is this function and deleting line 89. The other changes in this class are only cleanup. The bug is reported if hadObjectConstructor field is true in the second visit in reportConstructorThrow, which is set in the second visit, but it was only set back to false during the first visit.

Comment on lines +11 to +16
private static boolean verify() throws IOException {
// Returns true if data entered is valid, else throws an Exception
// Assume that the attacker just enters invalid data, so this method always throws the exception
throw new IOException("Invalid data!");
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It looks like this code example and ConstructorThrowNegativeTest16 were completely the same. So I'm changing it slightly.

@hazendaz hazendaz self-assigned this May 3, 2025
@hazendaz hazendaz added this to the Spotbugs 4.9.4 milestone May 3, 2025
@hazendaz hazendaz merged commit 045623a into spotbugs:master May 3, 2025
15 checks passed
@JuditKnoll JuditKnoll deleted the issue-3417 branch May 6, 2025 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positve CT_CONSTRUCTOR_THROW for "Compliant Solution (Java SE 6, Public and Private Constructors)"
3 participants