Skip to content

Conversation

JuditKnoll
Copy link
Collaborator

@JuditKnoll JuditKnoll commented Mar 27, 2025

The main method recognition is stuck in times before JEP 445 for several detectors. This PR fixes this problem by creating and calling one of the two applicable util methods.
I could not find any other usages of the string "main" in detectors, so hopefully all main method checks are addressed.


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

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

@@ -315,8 +316,7 @@ private void checkStateForLeakedObligations(State state, Map<Obligation, State>
private void reportWarning(Obligation obligation, State state, StateSet factAtExit) {
String className = obligation.getClassName();

if (methodDescriptor.isStatic() && "main".equals(methodDescriptor.getName())
&& "([Ljava/lang/String;)V".equals(methodDescriptor.getSignature())
if (MemberUtils.isMainMethod(xmethod)
Copy link
Collaborator Author

@JuditKnoll JuditKnoll Mar 27, 2025

Choose a reason for hiding this comment

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

Originally the methodDescriptor field is checked with the MethodDescriptor type, which has no function for checking the visibility (or at least I could not find it easily).

The function containing this check, reportWarning() is only called from analyzeMethod() in line 278:


In the same method before this call, the xmethod field is set from methodDescriptor in line 235:
xmethod = XFactory.createXMethod(methodDescriptor);

So I think using xmethod here instead of methodDescriptor should be okay.

@JuditKnoll JuditKnoll marked this pull request as ready for review March 27, 2025 13:21
@hazendaz hazendaz merged commit 4353e0b into spotbugs:master Mar 29, 2025
15 checks passed
@JuditKnoll JuditKnoll deleted the main branch March 31, 2025 06:39
@hazendaz hazendaz added this to the Spotbugs 4.9.4 milestone Apr 5, 2025
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.

3 participants