Hello ,

I tried to file this via the Issue tracker but maybe you need to login
to create a defect?

As you can see in the shortened stack trace below I have a Person
representation that I'm trying to encode with gzip.

Short aside:
This is one of several reasons why Factory methods are
better than constructors. It's easy to have unintentional side-effects
with constructors and subclasses. (Also why composition is preferred
to subclassing)

EncoderRepresentation(WrapperRepresentation).getWrappedRepresentation() line: 
289
EncoderRepresentation(WrapperRepresentation).getVariants() line: 280    
EncoderRepresentation(Representation).<init>(MediaType) line: 125       
EncoderRepresentation(Representation).<init>() line: 101        
EncoderRepresentation(WrapperRepresentation).<init>(Representation) line: 61    
EncoderRepresentation.<init>(Encoding, Representation) line: 60
Person.asJSON() line: 105

The way EncoderRepresentation subclasses WrapperRepresentation means
this isn't currently possible since getWrappedRepresentation is being
called from the superclasses constructor before it has been assigned
in EncoderRepresentation.

I'm not a big fan of adding null checks and duplicating code but this
will solve the problem, although in the end maybe it makes more sense
to restructure this code.

Few other things I noticed about the constructors:
Curious why nulls are being assigned to several of the fields in
Representation(MediaType) since these isn't needed.

Thoughts?
Chris
-- 
Chris Grindstaff | http://gstaff.org

Attachment: WrapperRepresentation.patch
Description: Binary data

Reply via email to