0 Replies Latest reply on May 23, 2006 2:04 PM by Hauke Stange

    Problems using Reflection within JBoss 4.0.4 GA (Tomcat Cont

    Hauke Stange Newbie

      Hi,

      i'm a little bit confused. Just migrated from JBoss 4.0.3 SP1 to 4.0.4 GA and all my reflection-using Servlets exploded with the following exception...

      19:45:53,263 ERROR [STDERR] java.lang.IllegalArgumentException
      19:45:53,263 ERROR [STDERR] at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
      19:45:53,263 ERROR [STDERR] at sun.reflect.UnsafeIntegerFieldAccessorImpl.set(UnsafeIntegerFieldAccessorImpl.java:57)
      19:45:53,263 ERROR [STDERR] at java.lang.reflect.Field.set(Field.java:656)
      19:45:53,263 ERROR [STDERR] at de.sung.servlet.ReflectionTest.doGet(ReflectionTest.java:28)
      19:45:53,263 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
      19:45:53,263 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      19:45:53,323 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      19:45:53,323 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      19:45:53,323 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      19:45:53,323 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      19:45:53,323 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      19:45:53,323 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      19:45:53,323 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      19:45:53,323 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      19:45:53,323 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      19:45:53,323 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      19:45:53,323 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      19:45:53,323 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      19:45:53,323 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      19:45:53,323 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      19:45:53,323 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      19:45:53,323 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      19:45:53,323 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      19:45:53,323 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
      19:45:53,323 INFO [STDOUT] value: 0
      


      Normally I deploy my WAR within an EAR but I built a simple WAR for testing those fuzzy reflection exceptions.

      the servlet
      package de.sung.servlet;
      
      import java.io.IOException;
      import java.lang.reflect.Field;
      
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      public class ReflectionTest extends HttpServlet {
      
       private int valueToSetByReflection;
      
       @Override
       protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
       Field fields[] = this.getClass().getDeclaredFields();
      
       for ( Field field : fields ) {
      
       if ( field.getName().equals("valueToSetByReflection") ) {
      
       if ( ! field.isAccessible() ) {
       field.setAccessible( true );
       }
      
       try {
       field.set("valueToSetByReflection", new Integer(1337) );
       } catch (IllegalArgumentException e) {
       e.getMessage();
       e.printStackTrace();
       } catch (IllegalAccessException e) {
       e.getMessage();
       e.printStackTrace();
       }
       }
      
       }
      
       System.out.println("value: " + valueToSetByReflection);
       }
      
      }
      


      the web.xml
      <web-app version="1.0">
      
       <display-name>Reflection Servlet Test</display-name>
       <description>Test for showing Reflection problems</description>
      
       <servlet>
       <servlet-name>ReflectionTest</servlet-name>
       <servlet-class>de.sung.servlet.ReflectionTest</servlet-class>
       <display-name>Reflection Test</display-name>
       </servlet>
      
       <servlet-mapping>
       <servlet-name>ReflectionTest</servlet-name>
       <url-pattern>/test</url-pattern>
       </servlet-mapping>
      
      </web-app>
      


      the war-file
      reflectiontest.war
       | META-INF
       | |_ MANIFEST.MF
       |
       | WEB-INF
       | |_ web.xml
       | |_ classes
       | |_ de.sung.servlet.ReflectionTest.class
      


      I hope you've some hints about that strange behaviour... Is it maybe a bug in the Tomcat?


      Regards,
      Hauke