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

Unused field not reported due to assumed reflection #2325

Closed
trancexpress opened this issue Jan 23, 2023 · 0 comments · Fixed by #2326
Closed

Unused field not reported due to assumed reflection #2325

trancexpress opened this issue Jan 23, 2023 · 0 comments · Fixed by #2326
Assignees
Labels

Comments

@trancexpress
Copy link
Contributor

Snippet to reproduce:

package test;
public class SomeClass {

	public static Class<?> cl = SomeClass.class;
	private String unusedField;
}

For unusedField, nothing is reported. After commenting out public static Class<?> cl = SomeClass.class;, a bug is reported as expected.

Seems to be coming from: 9ae2687

In particular as soon as LDC Ltest/SomeClass;.class is seen, SomeClass is assumed to be accessed with reflection and the change above suppresses the unused field bug report.

trancexpress added a commit to trancexpress/spotbugs that referenced this issue Jan 23, 2023
This change ensures an unused field is reported despite assumptions on
reflection use for the defining class.

If reflection is assumed, the priority of the created spotbugs problem
is lowered.

Fixes: spotbugs#2325
trancexpress added a commit to trancexpress/spotbugs that referenced this issue Jan 23, 2023
This change ensures an unused field is reported despite assumptions on
reflection use for the defining class.

In reflective classes, the priority of the created problem is lowered.

Fixes: spotbugs#2325
iloveeclipse pushed a commit that referenced this issue Jan 23, 2023
This change ensures an unused field is reported despite assumptions on
reflection use for the defining class.

In reflective classes, the priority of the created problem is lowered.

Fixes: #2325
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants