[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Field injection

alesj do-not-reply at jboss.com
Thu Mar 20 08:15:34 EDT 2008


"alesj" wrote : "adrian at jboss.org" wrote : Write the tests then you'll understand.
  |   | 
  | OK, the test is here, but it doesn't behave as I expect it to behave. :-(
  | 
I thought I had it, but nope. :-(
A different test code, similar wondering:

  |    public void testFieldAcessFromMain() throws Throwable
  |    {
  |       final FieldsClass tester = new FieldsClass();
  |       final ReflectFieldInfoImpl impl = new ReflectFieldInfoImpl();
  | 
  |       // I can't do setAccesible
  |       Field field = FieldsClass.class.getDeclaredField("privString");
  |       // let's try accessible
  |       try
  |       {
  |          field.setAccessible(true);
  |       }
  |       catch (Throwable t)
  |       {
  |          assertInstanceOf(t, AccessControlException.class);
  |       }
  |       // ok, setAccessible not set, so set should also fail
  |       try
  |       {
  |          field.set(tester, "foobar");
  |       }
  |       catch (Throwable t)
  |       {
  |          assertInstanceOf(t, IllegalAccessException.class);
  |       }
  | 
  |       impl.setField(field); // So I'll use this hole
  |       field = impl.getField(); // This should have an access check
  |       // why does this work?!?
  |       field.set(tester, "foobar");
  |       assertEquals("foobar", tester.getPrivString());
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138010#4138010

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4138010



More information about the jboss-dev-forums mailing list