Community

Issues using Javassist TypeInfoFactory in other projects

reply from Kabir Khan in JBoss Microcontainer Development - View the full discussion

It looks like ReflectMethodImpl.setMethod() and ReflectFieldImpl.setField() do that already:

RMI:

   public void setMethod(Method method)
   {
      boolean isDeclaringClassPublic = true;
      if (method != null)
      {
         accessCheck(Modifier.isPublic(method.getModifiers()));
         isDeclaringClassPublic = isDeclaringClassPublic(method);
         accessCheck(isDeclaringClassPublic);
      }
 
      this.method = method;
 
      if (method != null && (isPublic() == false || isDeclaringClassPublic == false))
         setAccessible();
   }

 

RFI:

   public void setField(Field field)
   {
      if (field != null)
         accessCheck(Modifier.isPublic(field.getModifiers()));
 
      this.field = field;
 
      if (isPublic() == false && field != null)
         setAccessible();
   }

 

Commenting out the whole block which threw the exception for JavassistMethodInfo, and setAccessible=true for ReflectMethodInfoImpl, works with both modes

 

org.jboss.test.kernel.deployment.support.StaticInjector:

 

   private void injectToMethod(Class<?> clazz, String method, Object value, Class<?> signature, boolean isPublic) throws Throwable
   {
      ClassInfo classInfo = configurator.getClassInfo(clazz);
      MethodInfo mi = Config.findMethodInfo(classInfo, method, new String[]{signature.getName()}, true, isPublic);
//      if (isPublic == false)
//      {
//         // TODO - move this into Reflection?
//         if (mi instanceof ReflectMethodInfoImpl)
//         {
//            ReflectMethodInfoImpl rmi = (ReflectMethodInfoImpl)mi;
//            Method  m = rmi.getMethod();
//            m.setAccessible(true);
//         }
//         else
//            throw new IllegalArgumentException("Cannot set accessible on method info: " + mi);
//      }
      mi.invoke(null, new Object[]{value});
   }

 

 

Reply to this message by going to Community

Start a new discussion in JBoss Microcontainer Development at Community