rharter / auto-value-gson

AutoValue Extension to add Gson De/Serializer support
Apache License 2.0
607 stars 103 forks source link

RV_RETURN_VALUE_IGNORED findbugs error #225

Closed codelibra closed 5 years ago

codelibra commented 5 years ago
@GenerateTypeAdapter
@AutoValue
public abstract class MyJava {

    public abstract String getSomething();
    public static MyJava create(String newSomething) {
        return new AutoValue_MyJava(newSomething);
    }
    public static TypeAdapter<MyJava> typeAdapter(final Gson gson) {
        return new MyJava_GsonTypeAdapter(gson);
    }
}
Gson gson = new GsonBuilder()
                    .registerTypeAdapterFactory(GenerateTypeAdapter.FACTORY)
                    .create();

gson.fromJson(jsonString, MyJava.class);

When building by java project i am getting findbugs error

<BugInstance type="RV_RETURN_VALUE_IGNORED" priority="2" rank="5" abbrev="RV" category="CORRECTNESS" >
    <ShortMessage>Method ignores return value</ShortMessage>
    <LongMessage>Return value of String.hashCode() ignored in ....MyJava_GsonTypeAdapter.read(JsonReader)</LongMessage>

Specifically error comes from the switch(_name) line. Could anyone help here?

ZacSweers commented 5 years ago

Hard to say without seeing the generated code. Switching on strings is fine though, your static analysis tool is the issue and best to file there.

codelibra commented 5 years ago

Error is shown from below switch(_name) in the generated java class


 while (jsonReader.hasNext()) {
      String _name = jsonReader.nextName();
      if (jsonReader.peek() == JsonToken.NULL) {
        jsonReader.nextNull();
        continue;
      }
      switch (_name) {
        default: {
ZacSweers commented 5 years ago

What is the generated auto value class code for that? Seems strange that the getSomething property is not getting picked up