danielwegener / danielwegener/xjc-guava-plugin

Private fields with accessible getters don't work

Open
#7 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
11
Forks
16
PR merge metrics
No merged PRs in 30d

Description

The problem can be reproduced with any xsd which contains a complexTypes with
``
and there are other complexTypes which extend those.

JAXB generates the following code for the `` definition:

```
@XmlAnyAttribute
private Map otherAttributes = new HashMap();
...
public Map getOtherAttributes() {
return otherAttributes;
}
```

The problem is that your plugin directly accesses the fields which only works for the top level class but not for the subclasses which cannot access the private field directly (for whatever reason JAXB is making this field private and not protected like the others)

The result is that hashcode+equals of subclasses include a non-accessible private field in their generated code which causes a compile error in the generated class.

Perhaps this can be fixed by always using the getters or by trying to find a getter if the field itself is not accessible (as a kind of fallback mechanism)

In my case I do not need this plugin for this specific xsd so I can live with the current behavior, but I still wanted to report the issue to let you (and other users) know it exists.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.