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

SpotBugs analysis: Holder.toString() may return null #2182

Closed
ghost opened this issue Jan 11, 2023 · 3 comments
Closed

SpotBugs analysis: Holder.toString() may return null #2182

ghost opened this issue Jan 11, 2023 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 11, 2023

Would returning "null", rather than null, be more idiomatic?

return obj != null ? "{" + obj + "}" : null;

toString method may return null
This toString method seems to return null in some circumstances. A liberal reading of the spec could be interpreted as allowing this, but it is probably a bad idea and could cause other code to break. Return the empty string or some other appropriate string rather than null.

Since at least 2.3.25.

Consider:

return obj == null ? "null" : "{" + obj + "}";
@mnriem
Copy link
Contributor

mnriem commented Sep 15, 2023

@DaveJarvis Would you consider "{}" instead as the Holder object itself does exist, but rather it has nothing to hold onto?

@mnriem
Copy link
Contributor

mnriem commented Sep 19, 2023

@DaveJarvis Can you create a PR for this?

@ghost
Copy link
Author

ghost commented Sep 19, 2023

@DaveJarvis Can you create a PR for this?

No, I'm moving off of GitHub soon.

arjantijms added a commit that referenced this issue Sep 22, 2023
SpotBugs analysis: Holder.toString() may return null #2182
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

No branches or pull requests

1 participant