[jboss-jira] [JBoss JIRA] Resolved: (JASSIST-40) Bug with 'insertAfter' called with 'asFinally' and the '$w' keyword on methods with a 'void' return type

Shigeru Chiba (JIRA) jira-events at lists.jboss.org
Fri Jan 4 11:58:05 EST 2008


     [ http://jira.jboss.com/jira/browse/JASSIST-40?page=all ]

Shigeru Chiba resolved JASSIST-40.
----------------------------------

    Resolution: Done

Thank you for this bug report.  The bug has been fixed.

> Bug with 'insertAfter' called with 'asFinally' and the '$w' keyword on methods with a 'void' return type
> --------------------------------------------------------------------------------------------------------
>
>                 Key: JASSIST-40
>                 URL: http://jira.jboss.com/jira/browse/JASSIST-40
>             Project: Javassist
>          Issue Type: Bug
>            Reporter: Patrice Bouillet
>         Assigned To: Shigeru Chiba
>
> Altering a method with a void return type by calling insertAfter containing the $_ keyword results in the following exception for example:
> Exception in thread "main" java.lang.VerifyError: (class: VoidReturnType, method: doNothing signature: ()V) Register 2 contains wrong type
> 	at java.lang.Class.getDeclaredConstructors0(Native Method)
> 	at java.lang.Class.privateGetDeclaredConstructors(Class.java:1618)
> 	at java.lang.Class.getConstructor0(Class.java:1930)
> 	at java.lang.Class.newInstance0(Class.java:278)
> 	at java.lang.Class.newInstance(Class.java:261)
> 	at InsertAfterAsFinally.main(InsertAfterAsFinally.java:16)
> The test source code to generate this error:
> public class InsertAfterAsFinally {
> 	public static void main(String[] args) {
> 		ClassPool cp = ClassPool.getDefault();
> 		try {
> 			CtClass cc = cp.get("VoidReturnType");
> 			CtMethod cm = cc.getDeclaredMethod("doNothing");
> 			cm.insertAfter("System.out.println(\"return value: \" + $_);", true);
> 			Class clazz = cc.toClass();
> 			VoidReturnType vrt = (VoidReturnType) clazz.newInstance();
> 			vrt.doNothing();
> 		} catch (NotFoundException e) {
> 			e.printStackTrace();
> 		} catch (CannotCompileException e) {
> 			e.printStackTrace();
> 		} catch (InstantiationException e) {
> 			e.printStackTrace();
> 		} catch (IllegalAccessException e) {
> 			e.printStackTrace();
> 		}
> 	}
> }
> public class VoidReturnType {
> 	void doNothing() {
> 	}
> }
> ========================================
> The problem seems to be in the insertAfterHandler method in the CtBehaviour class. The following modification from
> if (rtype.isPrimitive())
> to:
> if (rtype.isPrimitive() && (rtype != CtClass.voidType))
> fixes the error.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list