Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caused by: java.lang.IllegalAccessException - with modifiers "public" #153

Closed
helbertrios opened this issue Feb 20, 2014 · 1 comment
Closed
Assignees
Milestone

Comments

@helbertrios
Copy link

CAUSE:
When trying do conversion to an object with dynamic method.

Sample:
public AssociadoTO getAssociado() {

    Associado associado = new Associado() {
        public String getNome() {
            return "Helbert Rios";
        }
    };
    associado.setId(1);


    Mapper mapper = new DozerBeanMapper();
    return mapper.map(associado, AssociadoTO.class);
}

STACK:
org.dozer.MappingException: java.lang.IllegalAccessException: Class org.dozer.util.ReflectionUtils can not access a member of class br.helbert.as.AssociadoAS$1 with modifiers "public"
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82)
at org.dozer.util.ReflectionUtils.invoke(ReflectionUtils.java:295)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.invokeReadMethod(GetterSetterPropertyDescriptor.java:250)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.getPropertyValue(GetterSetterPropertyDescriptor.java:76)
at org.dozer.fieldmap.FieldMap.getSrcFieldValue(FieldMap.java:84)
at org.dozer.MappingProcessor.mapField(MappingProcessor.java:263)
at org.dozer.MappingProcessor.map(MappingProcessor.java:245)
at org.dozer.MappingProcessor.map(MappingProcessor.java:187)
at org.dozer.MappingProcessor.map(MappingProcessor.java:124)
at org.dozer.MappingProcessor.map(MappingProcessor.java:119)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:111)
at br.helbert.as.AssociadoAS.getAssociado(AssociadoAS.java:22)
at br.helbert.teste.Testex.main(Testex.java:10)
Caused by: java.lang.IllegalAccessException: Class org.dozer.util.ReflectionUtils can not access a member of class br.helbert.as.AssociadoAS$1 with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.reflect.Method.invoke(Method.java:588)
at org.dozer.util.ReflectionUtils.invoke(ReflectionUtils.java:287)
... 11 more
Exception in thread "main" org.dozer.MappingException: java.lang.IllegalAccessException: Class org.dozer.util.ReflectionUtils can not access a member of class br.helbert.as.AssociadoAS$1 with modifiers "public"
at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82)
at org.dozer.util.ReflectionUtils.invoke(ReflectionUtils.java:295)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.invokeReadMethod(GetterSetterPropertyDescriptor.java:250)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.getPropertyValue(GetterSetterPropertyDescriptor.java:76)
at org.dozer.fieldmap.FieldMap.getSrcFieldValue(FieldMap.java:84)
at org.dozer.MappingProcessor.mapField(MappingProcessor.java:263)
at org.dozer.MappingProcessor.map(MappingProcessor.java:245)
at org.dozer.MappingProcessor.map(MappingProcessor.java:187)
at org.dozer.MappingProcessor.map(MappingProcessor.java:124)
at org.dozer.MappingProcessor.map(MappingProcessor.java:119)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:111)
at br.helbert.as.AssociadoAS.getAssociado(AssociadoAS.java:22)
at br.helbert.teste.Testex.main(Testex.java:10)
Caused by: java.lang.IllegalAccessException: Class org.dozer.util.ReflectionUtils can not access a member of class br.helbert.as.AssociadoAS$1 with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.reflect.Method.invoke(Method.java:588)
at org.dozer.util.ReflectionUtils.invoke(ReflectionUtils.java:287)
... 11 more

SOLUTION:

org.dozer.util.ReflectionUtils

public static Object invoke(Method method, Object obj, Object[] args) {
Object result = null;
try {
method.setAccessible(Boolean.TRUE); // here
result = method.invoke(obj, args);
} catch (IllegalArgumentException e) {
if (e.getMessage().equals(IAE_MESSAGE)) {
MappingUtils.throwMappingException(prepareExceptionMessage(method, args), e);
}
MappingUtils.throwMappingException(e);
} catch (IllegalAccessException e) {
MappingUtils.throwMappingException(e);
} catch (InvocationTargetException e) {
MappingUtils.throwMappingException(e);
}
return result;
}

@lauriharpf lauriharpf self-assigned this Nov 23, 2014
@lauriharpf lauriharpf added this to the 5.5.2 milestone Nov 23, 2014
@lauriharpf
Copy link
Contributor

Hi @helbertrios,

thanks for a great bug-report. You're correct, Dozer doesn't seem to work with anonymous classes as one would expect. I'll merge the bugfix from @phdd and we'll release it in the next version.

lauriharpf added a commit that referenced this issue Nov 23, 2014
modifiers "public" #153), confirms that the fix in pull request #174 works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants