2 Replies Latest reply on Dec 29, 2009 7:15 AM by Gavin King

    Can't use AnnotationLiteral

    alberto Gori Novice

      I am triying to fire a qualified event programmatically.
      My qualifier:


      @Qualifier
      @Retention(RetentionPolicy.RUNTIME)
      @Target(ElementType.PARAMETER)
      public @interface MyQualifier {
           String value();
      }
      
      



      The AnnotationLiteral:


      public class MyAnnotation extends AnnotationLiteral<MyQualifier> {
           
           private String value;
      
           public MyAnnotation(String value) {
                this.value = value;
           }
      
           public String value() {
                return value;
           }
      
      }
      



      Where I fire the event:


      public class MyPhaseListener implements PhaseListener {
      
           @Override
           public void beforePhase(PhaseEvent event) {
                Util.getBeanManager().fireEvent(new MyEvent(), new MyAnnotation("item"));
           }
      
              ...
      
      }
      



      The observer method


           public void action(@Observes @MyQualifier("item") MyEvent event) {
                ...
           }
      




      I get this exception (on jetty)


      java.lang.RuntimeException: Error checking value of member method value on interface agori.example.MyQualifier
           at javax.enterprise.inject.AnnotationLiteral.invoke(AnnotationLiteral.java:169)
           at javax.enterprise.inject.AnnotationLiteral.hashCode(AnnotationLiteral.java:153)
           at java.util.HashMap.put(HashMap.java:372)
           at java.util.HashSet.add(HashSet.java:200)
           at java.util.AbstractCollection.addAll(AbstractCollection.java:305)
           at java.util.HashSet.<init>(HashSet.java:100)
           at org.jboss.weld.BeanManagerImpl.checkBindingTypes(BeanManagerImpl.java:620)
           at org.jboss.weld.BeanManagerImpl.resolveObserverMethods(BeanManagerImpl.java:600)
           at org.jboss.weld.BeanManagerImpl.fireEvent(BeanManagerImpl.java:837)
           at org.jboss.weld.BeanManagerImpl.fireEvent(BeanManagerImpl.java:831)
           at agori.example.RestFacesPhaseListener.beforePhase(RestFacesPhaseListener.java:18)
           at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:212)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:95)
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:311)
           at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
           at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
           at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
           at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
           at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
           at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
           at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
           at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
           at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:783)
           at org.apache.jsp.index_jsp._jspService(org.apache.jsp.index_jsp:46)
           at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
           at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
           at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486)
           at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
           at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
           at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
           at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
           at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
           at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
           at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
           at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
           at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
           at org.mortbay.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:500)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
           at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
           at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
           at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
           at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
           at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
           at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
           at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
           at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
           at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
           at org.mortbay.jetty.Server.handle(Server.java:326)
           at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
           at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
           at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
           at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
           at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
           at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
           at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
      
      



      What is wrong? The exception message is not very clear to me...