[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-1295) Entity component doesnt ensure that the the identifier field is accessible.
Chris Rudd (JIRA)
jira-events at lists.jboss.org
Mon May 7 13:34:52 EDT 2007
[ http://jira.jboss.com/jira/browse/JBSEAM-1295?page=comments#action_12361656 ]
Chris Rudd commented on JBSEAM-1295:
------------------------------------
I altered Entity.java :
public Entity(Class<?> beanClass)
{
super(beanClass);
for ( Class<?> clazz=beanClass; clazz!=Object.class; clazz = clazz.getSuperclass() )
{
for ( Method method: getBeanClass().getDeclaredMethods() )
{
//TODO: does the spec allow multiple lifecycle method
// in the entity class heirarchy?
if ( method.isAnnotationPresent(PreRemove.class) )
{
preRemoveMethod = method;
preRemoveMethod.setAccessible(true);
}
if ( method.isAnnotationPresent(PrePersist.class) )
{
prePersistMethod = method;
prePersistMehod.setAccessible(true);
}
if ( method.isAnnotationPresent(PreUpdate.class) )
{
preUpdateMethod = method;
preUpdateMethod.setAccessible(true);
}
if ( method.isAnnotationPresent(PostLoad.class) )
{
postLoadMethod = method;
postLoadMethod.setAccessible(true);
}
if ( method.isAnnotationPresent(Id.class) )
{
identifierGetter = method;
identifierGetter.setAccessible(true);
}
}
if (identifierGetter==null)
{
for ( Field field: getBeanClass().getDeclaredFields() )
{
if ( field.isAnnotationPresent(Id.class) )
{
identifierField = field;
identifierField.setAccessible(true);
}
}
}
}
}
Alternatly you could modify Reflections.java :
line 16
try
{
+ if( !method.isAccessible() )
+ method.setAccessible() )
return method.invoke( target, args );
line 45
try
{
+ if( !field.isAccessible() )
+ field.setAccessible() )
return field.get( target );
line 59
try
{
+ if( !field.isAccessible() )
+ field.setAccessible() )
field.set( target, value );
> Entity component doesnt ensure that the the identifier field is accessible.
> ---------------------------------------------------------------------------
>
> Key: JBSEAM-1295
> URL: http://jira.jboss.com/jira/browse/JBSEAM-1295
> Project: JBoss Seam
> Issue Type: Bug
> Affects Versions: 1.2.1.GA, 1.2.0.GA
> Reporter: Chris Rudd
>
> The Entity component uses reflection to get the identifier of that @Entity it represents. If the identifier is a private/protected @Id annotated field Entity.getIdentifier will fail with an IllegalAccessException.
> The code should be updated to call setAccessible(true) for each member / method that could be private/protected that will be accessed.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the seam-issues
mailing list