Bug 467793 - Constructor call must be a first statement inside a constructor even when the constructor is defined using inter-type declaration
Summary: Constructor call must be a first statement inside a constructor even when the...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.8.0   Edit
Hardware: PC Windows 8
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-20 22:16 EDT by Jiyong Park CLA
Modified: 2015-05-21 01:56 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jiyong Park CLA 2015-05-20 22:16:51 EDT
AspectJ compiler does not catch following case and causes java.lang.VerifyError at runtime.

Case: Constructor call is not a first statement inside a constructor added via inter-type declaration.

Example:

public class Example {
    Example() { /* default const */ }

    public static void main(String[] args) {
        new Example(1);
    }
}

aspect MyAspect {
    Example.new(int var) {
        System.out.println("Hello"); // do something before calling constructor
        this();
    }
}

Result:

Compiled without error, but following exception occurs at runtime.

Exception in thread "main" java.lang.VerifyError: Bad operand type when invoking <init>
Exception Details:
  Location:
    MyAspect.ajc$postInterConstructor$MyAspect$Example(LExample;I)V @9: invokespecial
  Reason:
    Invalid type: 'Example' (current frame, stack[0])
  Current Frame:
    bci: @9
    flags: { }
    locals: { 'Example', integer }
    stack: { 'Example' }
  Bytecode:
    0x0000000: b200 2212 28b6 002a 2ab7 0030 b1       

	at Example.<init>(Example.java:1)
	at Example.main(Example.java:5)