2 Replies Latest reply on Jul 11, 2011 12:34 PM by rimolive

    invalid method valueOf for target class java.lang.String

    rimolive

      Here is my Byteman rule:

       

      RULE Testing current variable content
      CLASS org.ajax4jsf.io.FastBufferReader
      METHOD writeTo(java.io.Writer)
      AT READ current
      BIND    buffer:FastBufferReader = $this;
              current:CharBuffer = buffer.current;
              nullCurr:CharBuffer = null;
              content:String = ""
      IF current != nullCurr
      DO debug(content.valueOf(current.getChars()).toString())
      ENDRULE
      

       

      But I'm receiving the following error:

       

      10:32:41,712 INFO  [STDOUT] Rule.ensureTypeCheckedCompiled : error type checking rule Testing current variable content
      org.jboss.byteman.rule.exception.TypeException: MethodExpression.typeCheck : invalid method valueOf for target class java.lang.String file /home/rmartinelli/JBoss/Community/Byteman-1.5.1/rule.txt line 29
                at org.jboss.byteman.rule.expression.MethodExpression.findMethod(MethodExpression.java:290)
                at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:172)
                at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:167)
                at org.jboss.byteman.rule.expression.MethodExpression.findMethod(MethodExpression.java:244)
                at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:172)
                at org.jboss.byteman.rule.Action.typeCheck(Action.java:106)
                at org.jboss.byteman.rule.Rule.typeCheck(Rule.java:505)
                at org.jboss.byteman.rule.Rule.ensureTypeCheckedCompiled(Rule.java:441)
                at org.jboss.byteman.rule.Rule.execute(Rule.java:652)
                at org.jboss.byteman.rule.Rule.execute(Rule.java:633)
                at org.ajax4jsf.io.FastBufferReader.writeTo(FastBufferReader.java:128)
                at org.ajax4jsf.io.parser.FastHtmlParser.parse(FastHtmlParser.java:169)
                at org.ajax4jsf.io.parser.FastHtmlParser.parseHtml(FastHtmlParser.java:230)
                at org.ajax4jsf.webapp.FilterServletResponseWrapper.parseContent(FilterServletResponseWrapper.java:594)
                at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:367)
                at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:295)
                at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:373)
                at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:500)
                at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
                at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
                at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
                at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
                at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:696)
                at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:667)
                at org.apache.jsp.index_jsp._jspService(index_jsp.java:59)
                at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
                at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
                at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:183)
                at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:95)
                at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:451)
                at java.lang.Thread.run(Thread.java:662)
      

       

      I know that java.lang.String has the valueOf() method, but it seems for byteman this method doesn't exists. Am I doing something wrong? I tried also using  new String() but the result is the same.

        • 1. Re: invalid method valueOf for target class java.lang.String
          adinn

          Hi Ricardo,

           

          It looks to me like you are using Byteman 1.5.1 (or possibly 1.5.0). If so then the error you are seeing is misleading you. It is happening because of a bug I introduced into these releases which stops the type checker correctly handling method overloading. The actual problem with your code is due to another bug though.

           

          Here is a simplified version of your rule which avoids reference to the ajax code

           

          RULE test
          CLASS java.lang.Object
          METHOD equals(Object)
          BIND current = "";
               chars = Character.toChars(32);
          IF TRUE
          DO debug(content.valueOf(chars).toString())
          ENDRULE
          

           

          When I type check this using the latest trunk release of script bmcheck I get the following

           

          [adinn@localhost trunk]$ bmcheck foo.btm
          checking rule test
          parsed rule "test" for class java.lang.Object
          ERROR : Failed to type check rule "test" loaded from foo.btm line 4
          org.jboss.byteman.rule.exception.TypeException: FieldExpression.typeCheck : invalid path content to static method valueOf file foo.btm line 7
              at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:120)
              at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:167)
              at org.jboss.byteman.rule.expression.MethodExpression.findMethod(MethodExpression.java:245)
              at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:172)
              at org.jboss.byteman.rule.Action.typeCheck(Action.java:106)
              at org.jboss.byteman.rule.Rule.typeCheck(Rule.java:523)
              at org.jboss.byteman.test.TestScript.checkRules(TestScript.java:315)
              at org.jboss.byteman.test.TestScript.testScript(TestScript.java:139)
              at org.jboss.byteman.test.TestScript.main(TestScript.java:98)
          
          TestScript: 1 total errors
                      0 total warnings
                      0 parse errors
                      1 type errors
                      0 type warnings
          [adinn@localhost trunk]$
          

           

          So, the real problem is that you are calling the static method valueOf via an instance (the object bound ot variable content) i.e. as if it were an instance method. Byteman does not accept this syntax. If you change the rule as follows

           

          RULE test
          CLASS java.lang.Object
          METHOD equals(Object)
          BIND current = "";
               chars = Character.toChars(32);
          IF TRUE
          DO debug(String.valueOf(chars).toString())
          ENDRULE
          

           

          then bmcheck accepts it ok

           

          [adinn@localhost trunk]$ bmcheck foo.btm
          checking rule test
          parsed rule "test" for class java.lang.Object
          type checked rule "test"
          
          TestScript: no errors
          [adinn@localhost trunk]$
          

           

          You may still fnd that when you try to call to String.valueOf() you still get an error because of the overloading bug. You can either buidl the trunk code (download and execute ant install in the root dir) or wait a week or two for 1.5.2 to come out.

          • 2. Re: invalid method valueOf for target class java.lang.String
            rimolive

            Hi Andrew,

             

            You are right, I'm using Byteman 1.5.1 in my tests. By the way, I tested your solution and it worked fine.

             

            Thanks for your help.

             

             

            Regards,

             

            Ricardo