interface weirdness
bblfish May 25, 2006 1:30 PMI 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?