Skip to content

PROPERTY_ACCESS_ERROR with Google AutoValue #548

@jonfreedman

Description

@jonfreedman

Google have a nice library AutoValue to generate immutable object model classes. To use this you create a public abstract class with abstract methods for each object property and at compile time an implementation is generated with package class access.

There are several issues when trying to use this library:

  • The Id attribute is not picked up without switching to MappingStyle.BEAN

  • The Id attribute is not picked up on an abstract method

  • Due to the way properties are looked up using reflection this results in IllegalAccessExceptions being throw from org.javers.common.reflection.JaversGetter. It would be possible to avoid this & potentially other polymorphic issues by traversing up the class hierarchy until you find a public class on which to perform reflection.

I have created a failing test here which fails with the InvocationTargetException.
If you move the @Id attribute from Animal#getJaversId to Animal#getName the tests fail with an ENTITY_WITHOUT_ID error.
If you remove .withMappingStyle(MappingStyle.BEAN).registerEntity(Animal.class) then the test will fail with id = 1.0 not Cat.

I would be happy to help fix this with some pointers.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions