David Harkness
2014-07-11 22:10:42 UTC
I have some objects that are deserialized from XML REST responses, and this
is tripping up FindBugs because it appears a String field is a constant
(it's package-private with no setter). Here's the relevant snippet:
@XmlRootElement(name = "response")
public XmlReponse {
String id = "";
@Nonnull
public String getId() {
if (Strings.isNullOrEmpty(id)) { // D'oh!
throw new InvalidResponseException("Received response without
ID");
}
return id;
}
}
Now I know I can use @SuppressFBWarnings on getId() for this, but I'm
wondering if there's a way to tell FindBugs that the id field can be
modified externally even though the code makes it look impossible. I can
change the field to public so FB assumes this, but is there another way?
Thanks,
David
is tripping up FindBugs because it appears a String field is a constant
(it's package-private with no setter). Here's the relevant snippet:
@XmlRootElement(name = "response")
public XmlReponse {
String id = "";
@Nonnull
public String getId() {
if (Strings.isNullOrEmpty(id)) { // D'oh!
throw new InvalidResponseException("Received response without
ID");
}
return id;
}
}
Now I know I can use @SuppressFBWarnings on getId() for this, but I'm
wondering if there's a way to tell FindBugs that the id field can be
modified externally even though the code makes it look impossible. I can
change the field to public so FB assumes this, but is there another way?
Thanks,
David