On line:
private boolean someFlag;
I get the following PMD warning:
Found non-transient, non-static member. Please mark as transient or provide accessors.
Can someone please explain why this warning is there and what it means? (I understand how to fix it, I don't understand why it's there...)
I'm getting this on many other member declarations as well...
EDIT: My class is definitely not a bean, and not serializable...
I assume your class is a bean that by definition implements Serializable
. A transient variable will be excluded from the serialization process. If you serialize and then deserialize the bean the value will be actually have the default value.
PMD assumes you are dealing with a serializable bean here. For a bean it is expected to have getters/setters for all member variables. As you have omitted these, you imply that your member variable is not part of the bean ....and so does not need to be serialized. If that is the case you should exclude it from the serialization. Which you do by marking the variable as "transient".
Now I get it.
After adding this definition:
private boolean someFlag;
...it is clear what happens here:
This error message does refer to the accessing schema. PMD states that classes referred to by beans, must also follow the bean schema.
Most likely to support property-style access like MyBean.referredClass.someFlag
will be translated to someObject.getReferredClass().getSomeFlag()
PMD it expects that there is a isSomeFlag/getSomeFlag
and setSomeFlag
method by which you could access its value, and not access it directly.
Found non-transient, non-static member. Please mark as transient **or provide accessors**.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With