ClassCastException in PropertyStates
-
When a com.serotonin.bacnet4j.type.constructed.ProptertyStates object is instantiated via the PropertyStates(int type, BaseType state) constructor, the getState() function will work fine as a BaseType object is required.
However, when a PropertyStates object is instantiated via the public PropertyStates(ByteQueue queue) constructor, the getState() function can generate ClassCastExceptions if it is not a BaseType.
In my case, I had a ClassCastException because this.state was a BinaryPV, which isn't a BaseType.
Changing
public BaseType getState() { return (BaseType) state.getDatum(); }
to this
public Encodable getState() { return state.getDatum(); }
resolves the problem. Or if getState returned this.state, that should probably work too.