Bug 115788 - NPE (CodeStream.java:3463)
Summary: NPE (CodeStream.java:3463)
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P2 blocker (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 110948 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-11-10 05:09 EST by Levente Mészáros CLA
Modified: 2005-11-23 06:15 EST (History)
1 user (show)

See Also:


Attachments
ajcore (38.15 KB, text/plain)
2005-11-10 05:10 EST, Levente Mészáros CLA
no flags Details
source excerpt (9.05 KB, application/x-zip-compressed)
2005-11-10 05:29 EST, Levente Mészáros CLA
no flags Details
Debug patch (47.13 KB, application/octet-stream)
2005-11-14 05:50 EST, Andrew Clement CLA
no flags Details
Debug log with patched compiler (31.38 KB, application/x-zip-compressed)
2005-11-14 06:02 EST, Levente Mészáros CLA
no flags Details
Second patch - includes stack at point where type cant be found (12.32 KB, application/octet-stream)
2005-11-14 07:17 EST, Andrew Clement CLA
no flags Details
Debug log (30.52 KB, application/x-zip-compressed)
2005-11-14 08:19 EST, Levente Mészáros CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Levente Mészáros CLA 2005-11-10 05:09:55 EST
See attached file.
Comment 1 Levente Mészáros CLA 2005-11-10 05:10:51 EST
Created attachment 29686 [details]
ajcore
Comment 2 Adrian Colyer CLA 2005-11-10 05:21:15 EST
Could you append some details about the source you were compiling at the time of the error please? Is it 
possible to narrow it down to a reproduceable test case that you can append?

I can see from the trace that the error is occurring whilst compiling an "if" statement if that is any help...

thanks, Adrian.
Comment 3 Levente Mészáros CLA 2005-11-10 05:29:14 EST
Created attachment 29687 [details]
source excerpt
Comment 4 Levente Mészáros CLA 2005-11-10 05:31:30 EST
It's not easy to narrow it down, so I have attached a few sources related, 
maybe it helps.
Comment 5 Eduardo Piveta CLA 2005-11-10 08:32:04 EST
Hi,

I was trying to narrow down the source code available in this bug when a
ParserException occured.
I created a simple test case about this problem.
I don't know if the bugs are related...
I'm using ajde 1.5.0.20051014142856

-------------------------------------------------
package a;

public aspect AAA perthis(this(Screen)){}   
-------------------------------------------------
org.aspectj.weaver.patterns.ParserException
at
org.aspectj.weaver.patterns.PatternParser.parseDottedNamePattern(PatternParser.java:897)
at
org.aspectj.weaver.patterns.PatternParser.parseSingleTypePattern(PatternParser.java:695)
at
org.aspectj.weaver.patterns.PatternParser.parseAtomicTypePattern(PatternParser.java:611)
at
org.aspectj.weaver.patterns.PatternParser.parseTypePattern(PatternParser.java:572)
at
org.aspectj.weaver.patterns.PatternParser.parseTypePattern(PatternParser.java:568)
at
org.aspectj.weaver.patterns.PerThisOrTargetPointcutVisitor.visit(PerThisOrTargetPointcutVisitor.java:140)
at
org.aspectj.weaver.patterns.ThisOrTargetPointcut.accept(ThisOrTargetPointcut.java:218)
at
org.aspectj.weaver.patterns.PerThisOrTargetPointcutVisitor.getPerTypePointcut(PerThisOrTargetPointcutVisitor.java:41)
at
org.aspectj.weaver.PerObjectInterfaceTypeMunger.getTestTypePattern(PerObjectInterfaceTypeMunger.java:46)
at
org.aspectj.weaver.PerObjectInterfaceTypeMunger.matches(PerObjectInterfaceTypeMunger.java:65)
at org.aspectj.weaver.ConcreteTypeMunger.matches(ConcreteTypeMunger.java:57)
at org.aspectj.weaver.bcel.BcelClassWeaver.weave(BcelClassWeaver.java:411)
at org.aspectj.weaver.bcel.BcelClassWeaver.weave(BcelClassWeaver.java:98)
at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1464)
at org.aspectj.weaver.bcel.BcelWeaver.weaveWithoutDump(BcelWeaver.java:1429)
at org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1203)
at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1021)
at
org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.weave(AjCompilerAdapter.java:300)
at
org.aspectj.ajdt.internal.compiler.AjCompilerAdapter.afterCompiling(AjCompilerAdapter.java:178)
at
org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$afterReturning$org_aspectj_ajdt_internal_compiler_CompilerAdapter$2$f9cc9ca0(CompilerAdapter.aj:70)
at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:367)
at
org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:759)
at
org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild(AjBuildManager.java:225)
at
org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:151)
at org.aspectj.ajde.internal.CompilerAdapter.compile(CompilerAdapter.java:122)
at
org.aspectj.ajde.internal.AspectJBuildManager$CompilerThread.run(AspectJBuildManager.java:191)

trouble in: 
public class a.AAA extends java.lang.Object:
  private static Throwable ajc$initFailureCause
  public void <init>():
                    ALOAD_0     // a.AAA this   (line 3)
                    INVOKESPECIAL java.lang.Object.<init> ()V
    constructor-execution(void a.AAA.<init>())
    |               RETURN
    constructor-execution(void a.AAA.<init>())
  end public void <init>()

  public static a.AAA aspectOf(Object)   
org.aspectj.weaver.AjAttribute$AjSynthetic@1a462b9
:
                    ALOAD_0
                    INSTANCEOF a.AAA$ajcMightHaveAspect
                    IFEQ L1
                    ALOAD_0
                    CHECKCAST a.AAA$ajcMightHaveAspect
                    INVOKEINTERFACE
a.AAA$ajcMightHaveAspect.ajc$a_AAA$perObjectGet ()La/AAA;
                    DUP
                    IFNULL L0
                    ARETURN
                L0: POP
                L1: NEW org.aspectj.lang.NoAspectBoundException
                    DUP
                    INVOKESPECIAL org.aspectj.lang.NoAspectBoundException.<init> ()V
                    ATHROW
  end public static a.AAA aspectOf(Object)

  public static boolean hasAspect(Object)   
org.aspectj.weaver.AjAttribute$AjSynthetic@1cdf14c
:
                    ALOAD_0
                    INSTANCEOF a.AAA$ajcMightHaveAspect
                    IFEQ L0
                    ALOAD_0
                    CHECKCAST a.AAA$ajcMightHaveAspect
                    INVOKEINTERFACE
a.AAA$ajcMightHaveAspect.ajc$a_AAA$perObjectGet ()La/AAA;
                    IFNULL L0
                    ICONST_1
                    IRETURN
                L0: ICONST_0
                    IRETURN
  end public static boolean hasAspect(Object)

  public static void ajc$perObjectBind(Object)   
org.aspectj.weaver.AjAttribute$AjSynthetic@17fbc00
:
                    ALOAD_0
                    INSTANCEOF a.AAA$ajcMightHaveAspect
                    IFEQ L0
                    ALOAD_0
                    CHECKCAST a.AAA$ajcMightHaveAspect
                    INVOKEINTERFACE
a.AAA$ajcMightHaveAspect.ajc$a_AAA$perObjectGet ()La/AAA;
                    IFNONNULL L0
                    ALOAD_0
                    CHECKCAST a.AAA$ajcMightHaveAspect
                    NEW a.AAA
                    DUP
                    INVOKESPECIAL a.AAA.<init> ()V
                    INVOKEINTERFACE
a.AAA$ajcMightHaveAspect.ajc$a_AAA$perObjectSet (La/AAA;)V
                L0: RETURN
  end public static void ajc$perObjectBind(Object)

end public class a.AAA

when weaving type a.AAA
when weaving aspects 
when weaving 
when batch building
BuildConfig[D:\piveta\plugInWorkspace\.metadata\.plugins\org.eclipse.ajdt.core\BugsAspectj113066.generated.lst]
#Files=4
Comment 6 Andrew Clement CLA 2005-11-14 04:48:38 EST
I've fixed the parser error that Eduardo demonstrated - I dont think it is
related to the original problem.

The original problem is this exception:

java.lang.NullPointerException
  at oaoejic.codegen.CodeStream.invokestatic(CodeStream.java:3463)
  at oaoejic.ast.MessageSend.generateCode(MessageSend.java:137)
  at oaoejic.ast.EqualExpression.generateOptimizedNonBooleanEqual(Line 349)
  at oaoejic.ast.EqualExpression.generateOptimizedBoolean(Line 182)
  at oaoejic.ast.IfStatement.generateCode(IfStatement.java:148)
  at oaoejic.ast.Block.generateCode(Block.java:58)
  at oaoejic.ast.IfStatement.generateCode(IfStatement.java:160)
  at oaoejic.ast.AbstractMethodDeclaration.generateCode(226)
  at oaoejic.ast.AbstractMethodDeclaration.generateCode(173)
  at oaoejic.ast.TypeDeclaration.generateCode(TypeDeclaration.java:568)
  at oaoejic.ast.AspectDeclaration.generateCode(AspectDeclaration.java:279)

Line 3463 in CodeStream is:

if (((id = methodBinding.returnType.id) == T_double) || (id == T_long))

given that the methodbinding is used earlier in the CodeStream.invokestatic
method then we know the methodbinding isnt null.  So, the returnType for the
methodbinding must be null.  When I've seen badly formed methodbindings in the
code before, it has usually been a sign of syntax error in the code but the
compiler is crashing like this before it can be reported.

From the stack trace, we can also see this happens whilst generating code for an
aspect - and we can see it happens whilst generating code for an if expression.

We can't tell if its whilst generating the body of an ITD or generating the body
of a regular method because generateCode(ClassFile) isn't overridden in the ITD
hierarchy (maybe thats the problem?)

Is there any way you can build a subset of your application (take out a few of
the aspects) to try and narrow this problem down? Or are they too co-dependent?

If that doesnt work then the best we can do is probably a debug build that tells
us which method it is crashing on whilst generating code - if I give you a patch
for AspectJ to turn on debug, can you apply it and retry creating the problem
for me?
Comment 7 Levente Mészáros CLA 2005-11-14 05:06:29 EST
I can't narrow it down easily. Also, I forgot to say that it compiles and 
works with AspectJ 1.2.1 which might be a very important note.

If you can send the debug AspectJ version we can try that and send the logs.

Another option is that we package that part of the application that does not 
compile with AspectJ 1.5 and send it to you. Please note that there will be 
other errors (already seen before) too, despite of that the whole application 
compiles with AspectJ 1.2.1. But first I have to talk my boss first.

levy
Comment 8 Andrew Clement CLA 2005-11-14 05:27:23 EST
I will create a patch to give us more diagnostics.  But if you could send me the
application source that fails with 1.5 and builds ok with 1.2.1 then that would
be a much faster way for me to work - you should probably mail it to me directly
rather than attaching to bugzilla.
Comment 9 Andrew Clement CLA 2005-11-14 05:50:23 EST
Created attachment 29855 [details]
Debug patch

This zip contains 2 classes - you should go into your aspectj installation
(possibly c:\aspectj1.5\lib) and create a backup of aspectjtools.jar, then
unzip this patch in that directory, giving you an 'org' subfolder.  Then update
aspectjtools.jar with the two files from the patch, with a command like:

jar -uvf aspectjtools.jar org

Once patched, when a build occurs we will get a load of diagnostics about the
code generation that is occurring - hopefully the bit just before the NPE will
tell us which class and which method is causing the problem.

If you are using AJDT rather than the command line, then the patch should be
applied to ajde.jar in the org.aspectj.ajde plugin in your eclipse plugins
directory (backup ajde.jar before patching it)
Comment 10 Levente Mészáros CLA 2005-11-14 06:02:11 EST
Created attachment 29856 [details]
Debug log with patched compiler
Comment 11 Levente Mészáros CLA 2005-11-14 06:02:24 EST
Debug log attached.
Comment 12 Andrew Clement CLA 2005-11-14 06:25:39 EST
thanks for doing that so quickly!!

Fails codegen for:
invokestatic:NULL TYPE
ajc$interMethodDispatch1$com_netvisor_common_UserMessageMixin$
    com_netvisor_common_UserMessage$getSeverity(com.netvisor.common.UserMessage) 

as we can see, the return type is null.


The invoke occurs in:
actionPerformedExceptionHandler()

which is in:
com/netvisor/web_framework/components/FormMessages$IFormMessages


In actionPerformedExceptionHandler:
> UserMessage e = (UserMessage)exception;
>
> if (e.getSeverity() == UserMessage.MESSAGE)

we are blowing up creating the code to invoke getSeverity() on the UserMessage.

The original attachment of source doesn't include 'UserMessage' - can you take a
look at the ITD that puts getSeverity() onto UserMessage and maybe attach the
related source?
Comment 13 Levente Mészáros CLA 2005-11-14 06:51:31 EST
There's no magic in there. Please note the can't find int message of your 
debug log. I think the problem starts from there.

Anyway, I have sent you a part of the project which compiles on its own. Try 
that one if this doesn't help.

Thanks for your help,
levy

ps: BTW: I think the source I have sent is a good test case for the AspectJ 
compiler.

package com.netvisor.common;

import java.lang.RuntimeException;

public interface UserMessage
{
	public static final int MESSAGE = 0;
	public static final int WARNING = 1;
	public static final int ERROR = 2;
	
	public Object[]		getParams();
	public void			setParams(Object[] params);
	
	public String		getUserMessage();
	public void			setUserMessage(String 
messageKeyOrText);
	
	public int			getSeverity();
	public void			setSeverity(int severity);
}






package com.netvisor.common;

import java.lang.RuntimeException;

public abstract aspect UserMessageMixin
{
	declare precedence: UserMessageMixin;
	
	private Object[]	UserMessage.params;
	private String		UserMessage.message;
	private int			UserMessage.severity;
	
	public Object[] UserMessage.getParams()
	{
		return params;
	}
	public void UserMessage.setParams(Object[] params)
	{
		this.params = params;
	}
	
	public String UserMessage.getUserMessage()
	{
		return message;
	}
	public void UserMessage.setUserMessage(String messageKeyOrText)
	{
		this.message = messageKeyOrText;
	}
	
	public int UserMessage.getSeverity()
	{
		return severity;
	}
	public void UserMessage.setSeverity(int severity)
	{
		this.severity = severity;
	}
}

Comment 14 Andrew Clement CLA 2005-11-14 07:16:27 EST
Yes, I agree with you, the 'cant find: int' is the initial problem we need to
resolve - given that getSeverity() returns an int.  I can't recreate with those
two files though.

There is only one place in the compiler that can put out that message - so I'm
going to attach one more class to patch into your AspectJ - this will give us a
stack trace at the point where the type cannot be found.

I'll also try recreating it with the code you sent me when it arrives - I assume
you sent it to my gmail ID:
  andrew.clement@gmail.com
Comment 15 Andrew Clement CLA 2005-11-14 07:17:52 EST
Created attachment 29857 [details]
Second patch - includes stack at point where type cant be found

Apply in the same way as the previous one.  With the 'cant find: int' messages
there should now be a stack trace indicating how we got into that situation.
Comment 16 Levente Mészáros CLA 2005-11-14 08:19:16 EST
Created attachment 29862 [details]
Debug log

Second log for can't find int message
Comment 17 Levente Mészáros CLA 2005-11-14 08:20:04 EST
Did you get my e-mail with the workspace included?
Comment 18 Andrew Clement CLA 2005-11-14 11:08:56 EST
Fix checked in - thanks to Levy I managed to recreate the problem locally.  It
was to do with our handling of primitives - in this particular case we were
'forgetting' in one case that 'I' was a primitive type and treating it as a
reference type (like String or Object).

fix will be in next dev build.
Comment 19 Levente Mészáros CLA 2005-11-15 04:42:17 EST
Thanks for the fix, I've checked it and it works with Java target version 1.4, 
but not with 1.5.

You can try it by changing the value of 
<property name="target.java.version" 		value="1.5"/>
in the file
AA\Workspace\Repository\common h3\common-build-properties.xml
of the package I sent to you.

You will receive the following errors (but only with 1.5 target version):

   [mkdir] Created dir: C:\AA\Workspace\Repository\web-framework\build\web-
compiled
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\GridScreen.java:11 
[error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] public class GridScreen extends Grid
    [iajc]              ^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\GridScreen.java:11 
[error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] public class GridScreen extends Grid
    [iajc]              ^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\GroupBoxScreen.java:14
 [error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] public class GroupBoxScreen extends GroupBox
    [iajc]              ^^^^^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\GroupBoxScreen.java:14
 [error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] public class GroupBoxScreen extends GroupBox
    [iajc]              ^^^^^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\Screen.java:3 [error] 
Duplicate methods named actionPerformed with the parameters (ActionEvent) and 
(ActionEvent) are defined by the type HidingMessagesMixin.IHidingMessages
    [iajc] public interface Screen extends MutableContent {};
    [iajc]                  ^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\Screen.java:3 [error] 
Duplicate methods named actionPerformed with the parameters (ActionEvent) and 
(ActionEvent) are defined by the type HidingMessagesMixin.IHidingMessages
    [iajc] public interface Screen extends MutableContent {};
    [iajc]                  ^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\ScreenTitleMixin.java:
26 [error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] private interface ScreenTitle extends Screen {};
    [iajc]                   ^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\ScreenTitleMixin.java:
26 [error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] private interface ScreenTitle extends Screen {};
    [iajc]                   ^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\ScreenWithButtons.java
:27 [error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] public class ScreenWithButtons extends SimpleScreen
    [iajc]              ^^^^^^^^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\ScreenWithButtons.java
:27 [error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] public class ScreenWithButtons extends SimpleScreen
    [iajc]              ^^^^^^^^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\ScreenWithTitle.java:1
2 [error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] public class ScreenWithTitle extends Panel
    [iajc]              ^^^^^^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\ScreenWithTitle.java:1
2 [error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] public class ScreenWithTitle extends Panel
    [iajc]              ^^^^^^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\SimpleScreen.java:11 
[error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] public class SimpleScreen extends Panel
    [iajc]              ^^^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\components\SimpleScreen.java:11 
[error] Duplicate methods named actionPerformed with the parameters 
(ActionEvent) and (ActionEvent) are defined by the type 
HidingMessagesMixin.IHidingMessages
    [iajc] public class SimpleScreen extends Panel
    [iajc]              ^^^^^^^^^^^
    [iajc] C:\AA\Workspace\Repository\web-
framework\src\java\com\netvisor\web_framework\wizard\WizardAspect.java:65 
[error] The method add(E) in the type List<E> is not applicable for the 
arguments (WizardStage)
    [iajc] this.stages.add(stage);
Comment 20 Andrew Clement CLA 2005-11-15 05:24:50 EST
Interesting!  This is exactly the same as bug 110948 which I couldnt reproduce
before and so closed as WORKSFORME - I'll take a look at debugging it now I have
a test that should show the problem.
Comment 21 Levente Mészáros CLA 2005-11-15 07:16:55 EST
Well, the guy who sent that bug just sits next to me... ;-)
Comment 22 Andrew Clement CLA 2005-11-18 11:21:47 EST
*** Bug 110948 has been marked as a duplicate of this bug. ***
Comment 23 Andrew Clement CLA 2005-11-23 04:20:50 EST
what a nightmare.  but I've fixed it all now.  The duplicate methods stuff is due to an over eager method verifier not allowing for ITDs.  That then uncovered a very subtle problem where a ITD that used the raw type list ended up being interpreted later as a reference to the generic type.

Fixes all checked in. waiting on build.
Comment 24 Levente Mészáros CLA 2005-11-23 05:02:35 EST
Well, thanks a lot. I will try it as soon as the next developer release is available on the web site.

Unfortunately or (well I think rather luckily for testing purposes?!) we still have a couple of components to be compiled under Java 1.5 and AspectJ 1.5. These components have never compiled before successfully with 1.5 because they were dependent on the component for which you have just fixed this bug...

levy
Comment 25 Andrew Clement CLA 2005-11-23 06:15:04 EST
fixes available in latest dev build.