Bug 40589 - Default method impl for interface causes internal exception.
Summary: Default method impl for interface causes internal exception.
Status: RESOLVED DUPLICATE of bug 39993
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.1.0   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Jim Hugunin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-22 10:07 EDT by George Harley CLA
Modified: 2003-07-23 12:47 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 George Harley CLA 2003-07-22 10:07:44 EDT
Using AspectJ 1.1.0 on Windows, if I create an aspect that contains a 
declaration of an empty interface "I" and then supply a default implementation 
of the clone() method for the interface then an internal compiler error occurs 
at build time. 

Here is the simplest test case I can make :-

public aspect MyAspectA
{
    protected interface I {}
    
    public Object I.clone() throws CloneNotSupportedException {   
        return super.clone();
    }
}

When I run ajc against the above class I get the following output ..

java.lang.NullPointerException
at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.
java:40)
at org.eclipse.jdt.internal.compiler.ast.ReturnStatement.
analyseCode(ReturnStatement.java:37)
at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.
analyseCode(MethodDeclaration.java:70)
at org.aspectj.ajdt.internal.compiler.ast.InterTypeMethodDeclaration.
analyseCode(InterTypeMethodDeclaration.java:58)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.
internalAnalyseCode(TypeDeclaration.java:639)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.
analyseCode(TypeDeclaration.java:196)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.
analyseCode(CompilationUnitDeclaration.java:78)
at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:541)
at org.aspectj.ajdt.internal.compiler.AjCompiler.process(AjCompiler.java:65)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:338)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.
performCompilation(AjBuildManager.java:372)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuildManager.
java:133)
at org.aspectj.ajdt.internal.core.builder.AjBuildManager.
batchBuild(AjBuildManager.java:78)
at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:106)
at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
at org.aspectj.tools.ajc.Main.run(Main.java:217)
at org.aspectj.tools.ajc.Main.runMain(Main.java:155)
at org.aspectj.tools.ajc.Main.main(Main.java:72)

Please note that I have run the same aspect through the 1.0.6 AspectJ compiler 
without any problems.
Comment 1 George Harley CLA 2003-07-22 10:10:07 EDT
Forgot to mention in my original report that if the single line of code inside 
the clone() method (return super.clone()) is replaced with the line "return 
null" then the aspect will compile OK on 1.1.0. 
Comment 2 Jim Hugunin CLA 2003-07-22 13:32:00 EDT
General form of the bug is whenever Object methods are called from methods 
introduced on an interface.

*** This bug has been marked as a duplicate of 39993 ***
Comment 3 George Harley CLA 2003-07-23 09:22:56 EDT
Here are two related patches that add a test for this problem to the AspectJ 
testing harness. I've had to split the patch into two because with all of the .
ajesym files that were created in my workspace from running the tests my first 
pass at a patch was too big to paste into this note.

Patch 1 of 2
-----------------

Index: georgeTests.xml
===================================================================
RCS file: georgeTests.xml
diff -N georgeTests.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ georgeTests.xml	23 Jul 2003 10:25:54 -0000
@@ -0,0 +1,9 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd">
+<suite> 
+    <ajc-test dir="bugs" pr="40589"
+   	 title="Default method impl for interface causes internal exception.">
+        <compile files="CloneMethod.java"/>
+        <run class="CloneMethod"/>
+    </ajc-test>
+
+</suite>
\ No newline at end of file


Patch 2 of 2
-----------------

Index: CloneMethod.java
===================================================================
RCS file: CloneMethod.java
diff -N CloneMethod.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CloneMethod.java	23 Jul 2003 10:26:38 -0000
@@ -0,0 +1,58 @@
+aspect AspectA {
+	protected interface I {
+	}
+
+	declare parents : MyString implements I;
+
+	protected Object createCloneFor(I object) {
+		if (object instanceof MyString) {
+			return new MyString(((MyString) object).toString());
+		} else {
+			return null;
+		}
+	}
+
+	public Object I.clone() throws CloneNotSupportedException {
+		return super.clone();
+//		return null;
+	}
+
+	public Object cloneObject(I object) {
+		try {
+			return object.clone();
+		} catch (CloneNotSupportedException ex) {
+			return createCloneFor(object);
+		}
+	}
+}
+
+class MyString implements Cloneable {
+
+	protected String text;
+
+	public MyString(String init) {
+		text = init;
+	}
+
+	public void setText(String newText) {
+		text = newText;
+	}
+
+	public String toString() {
+		return "MyString: " + text;
+	}
+}
+
+public class CloneMethod {
+
+	public static void main(String[] args) {
+		MyString orig1;
+		MyString copy1;
+
+		orig1 = new MyString("  This is I 1");
+		copy1 = (MyString) AspectA.aspectOf().cloneObject(orig1);
+		orig1.setText("  This is I 2");
+		copy1.setText("  This is Clone 1");
+		System.out.println("... done.");
+	}
+}

Comment 4 Jim Hugunin CLA 2003-07-23 12:47:43 EDT
Great.  This test has been added to the tree, and it also passes with the 
existing fix.

This patch was extremely easy to apply.  Only one comment.  For patches that 
you submit, you should put the test case in either ajcTests.xml or 
ajcTestsFailing.xml depending on the status rather than creating a new file.  
jimTests.xml is a convenience file that I use locally for playing around with 
things.  I'm going to remove it from the tree so that it won't confuse others 
in the future.