1 Reply Latest reply on Nov 5, 2008 7:11 PM by Filippo Bannò

    interface weirdness

    Henry Story Newbie

      I have code that works when it calls a method on an implementation of an interface but not when it calls the same method on the interface directly.

      When calling the method on its interface I get the following error when testing my class

      java.lang.VerifyError: (class: eg/test/atom/MetaData, method: addAuthor signatur
      e: (Leg/test/atom/Person;)V) Inconsistent args_size for opc_invokeinterface
       at eg.test.PojoTest.buildEntry1(PojoTest.java:96)
       at eg.test.PojoTest.buildEntry1v2(PojoTest.java:122)
      ...
      



      The relevant code is

       StringBuilder code = new StringBuilder();
       code.append("{ System.out.println(\"in field rewriter\");");
       code.append(" com.sun.labs.rdf.sommer.RewriteMapper map = " +
       "com.sun.labs.rdf.sommer.MapperManager#getMappingForObject($0); ");
       code.append(" System.out.println(\"map=\"+map);");
       if (arg.isWriter()) {
       code.append(" if ( map == null ) { System.out.println(\"proceeding!\"); " +
       " $proceed($$); " +
       " System.out.println(\"proceeded!\"); } else { ");
       if (isCollection(arg.getField().getType())) {
       String line = format(" $0.{0} = ( {1} ) map.setCollectionField( " +
       " $0, \"{2}\", {3}, " +
       " $1, {4}, {5}.class.getField( \"{0}\" ).getGenericType() ); ",
       arg.getFieldName(),
       arg.getField().getType().getName(),
       field.value(),
       field.inverse(),
       !containsFunctional(annotations),
       arg.getField().getDeclaringClass().getName());
       code.append("try { "+line+ " } catch ( java.lang.NoSuchFieldException e) { }");
      
      


      everything compiles ok and I get the following output

      {
       System.out.println("in field rewriter");
       com.sun.labs.rdf.sommer.RewriteMapper map = com.sun.labs.rdf.sommer.MapperManager#getMappingForObject($0);
       System.out.println("map="+map);
       if ( map == null ) {
       System.out.println("proceeding!");
       $proceed($$);
       System.out.println("proceeded!");
       } else {
       try {
       $0.authors = ( java.util.Collection ) map.setCollectionField(
       $0, "http://www.w3.org/2005/10/23/Atom#author",false,
       $1, true,
       eg.test.atom.MetaData.class.getField( "authors" ).getGenericType() );
       } catch ( java.lang.NoSuchFieldException e) { }
      


      (I have prettyfied the above to make it clearer)

      Running exactly the same code except for changing the type of
      map to the implementation class, the error dissapears.

      This took quite some time to work out.
      Any ideas?



        • 1. Re: interface weirdness
          Filippo Bannò Newbie

          I have had the same problem. I have a class which contains this code:

          List x = new ArrayList();
          x.add(new ArrayList());

          and I instrument it with an editor which replaces the call to method add with:
          "$_ = ($r)$proceed($1 instanceof java.lang.Object ? $1 : $1);"

          When I run the program, the loading of the class generates the error:
          Exception in thread "main" java.lang.VerifyError: (class: Test, method: main signature: ([Ljava/lang/String;)V) Inconsistent args_size for opc_invokeinterface

          If the type of variable x is "AbstractList" instead of "List", the program runs normally.
          I did some experiments and I think the "cond ? ex1 : ex2" expression is the cause of the problem... but why?