You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
CAUSE:
When trying do conversion to an object with dynamic method.
Sample:
public AssociadoTO getAssociado() {
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;
}
The text was updated successfully, but these errors were encountered: