Bug 327931 - [DOM] SimpleName#resolveConstantExpressionValue() returns null for inherited constant values
Summary: [DOM] SimpleName#resolveConstantExpressionValue() returns null for inherited ...
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.7 M7   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
: 338390 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-10-15 13:46 EDT by Cedric Beust CLA
Modified: 2011-04-26 03:03 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cedric Beust CLA 2010-10-15 13:46:43 EDT
Build Identifier: I20100608-0911

resolveConstantExpressionValue() returns null if the constant value is inherited from a base class but works as expected when that constant value is in the same class as the node.


Reproducible: Always

Steps to Reproduce:
I have an annotation that takes an array of strings:

@Test(groups = "a")

If I declare this string in a static field of a base class instead:

public class A {
  public static final String NAME = "a";
}

public class B extends A {
  @Test(groups = NAME)
}

then calling resolveConstantExpressionValue() on the node that represents the attribute (a SimpleName) returns null.

If I move the field into the same class the annotation is located, resolveConstantExpressionValue() returns the expected value ("a"):

public class B {
  public static final String NAME = "a";
  @Test(groups = NAME)
}
Comment 1 Olivier Thomann CLA 2010-10-15 14:14:17 EDT
Will investigate.
Comment 2 Olivier Thomann CLA 2010-10-15 14:32:33 EDT
So you have no declaration (field, method, type) behind the annotation?
public class B extends A {
  @Test(groups = NAME)
}
Comment 3 Olivier Thomann CLA 2010-10-15 14:39:14 EDT
Right now I cannot reproduce the failure.
Could you please send me a small project that shows the problem ?
Thanks.
Comment 4 Olivier Thomann CLA 2010-10-15 14:43:34 EDT
In the case:
public class A {
  public static final String NAME = "a";
}

public class B extends A {
  @Test(groups = NAME)
}

Are you using A from source or from binaries when you create the DOM for B?
Comment 5 Olivier Thomann CLA 2010-10-15 14:50:17 EDT
I tried with A from source or from binary and it worked in both cases. I cannot reproduce the null case.
Would it be possible for you to try a newer build ?
Comment 6 Cedric Beust CLA 2010-10-15 16:49:56 EDT
Hi Olivier,

Yes, let me try a newer build. Do you have one to recommend?
Comment 7 Cedric Beust CLA 2010-10-15 17:06:13 EDT
Olivier,

I just tried with the latest stable Indigo and I'm still seeing the problem.

How to reproduce:

- Install the TestNG Eclipse plug-in (http://github.com/cbeust/testng-eclipse)
- Set a breakpoint in AnnotationVisitor:93:

          else if (value instanceof SimpleName) {
            Object boundValue = value.resolveConstantExpressionValue();
            addGroup(boundValue.toString());
          }

- Run the plug-in, create two classes A and B as shown above (the base class defines the static final String, the subclass defines a method with @Test(groups = A)
- Right click on the class, "Run as..." / "TestNG"
- Observe that boundValue is null in line 93

Let me know if you need more help in reproducing this problem.
Comment 8 Olivier Thomann CLA 2010-10-18 09:33:57 EDT
(In reply to comment #7)
> - Run the plug-in, create two classes A and B as shown above (the base class
> defines the static final String, the subclass defines a method with
> @Test(groups = A)
Could you please describe how you set up the two classes and the project in which they belong?
Would it be possible for you to attach such a test project ?

I tried the steps and I still get a right value.
Comment 9 Olivier Thomann CLA 2010-10-18 09:34:59 EDT
(In reply to comment #8)
> (In reply to comment #7)
> > - Run the plug-in, create two classes A and B as shown above (the base class
> > defines the static final String, the subclass defines a method with
> > @Test(groups = A)
> Could you please describe how you set up the two classes and the project in
> which they belong?
> Would it be possible for you to attach such a test project ?
> 
> I tried the steps and I still get a right value.
When I run the class B, it doesn't find any test to run, but it reaches the breakpoint on line 93.
Comment 10 Olivier Thomann CLA 2010-10-19 09:26:41 EDT
Cedric, I am missing something to reproduce this issue.
Would it be possible for you to provide a small project that exhibits the problem?
As soon as I can reproduce, I'll work on it to get it fixed. Ideally for M3.
Thanks.
Comment 11 Cedric Beust CLA 2010-10-19 12:36:12 EDT
Hi Olivier,

I can't reproduce the issue on my laptop (I originally found it on my desktop, as did the TestNG user that reported it in the first place).

I'm away from my desk for the week so I suggest we close this issue for now and next week when I'm back at my desk, I'll confirm it doesn't work there and I'll reopen it with an attached project and maybe a bit more clue as to why it's only failing in certain conditions.

Thanks for your help, Olivier.
Comment 12 Olivier Thomann CLA 2010-10-19 13:00:08 EDT
Ok. Closing as WORKSFORME.
Please reopen if you get it again or have more clue on what is going on.
Comment 13 Satyam Kandula CLA 2010-10-26 08:17:32 EDT
Verified for 3.7M3 as per user comment
Comment 14 Olivier Thomann CLA 2010-11-01 12:24:07 EDT
(In reply to comment #11)
> I'm away from my desk for the week so I suggest we close this issue for now and
> next week when I'm back at my desk, I'll confirm it doesn't work there and I'll
> reopen it with an attached project and maybe a bit more clue as to why it's
> only failing in certain conditions.
Any update on this ?
Comment 15 Cedric Beust CLA 2010-11-01 12:26:42 EDT
Hi Olivier,

Sorry, I've been sidetracked into oblivion and I haven't had the time to get back to this. I have an open TestNG bug about this so I will get back to it eventually :-)
Comment 16 Olivier Thomann CLA 2011-02-28 11:25:22 EST
*** Bug 338390 has been marked as a duplicate of this bug. ***
Comment 17 Olivier Thomann CLA 2011-02-28 11:26:10 EST
Reopening for further investigation once a test case from bug 338390 is providedé
Comment 18 Olivier Thomann CLA 2011-03-07 10:53:20 EST
Please provide a test case to fix this bug.
Comment 19 martin CLA 2011-03-07 14:14:42 EST
hi,
i tried to implement a simple maven project with some testng tests, but somehow I cannot reproduce this bug with a new project.
This is reproducable (not always, but surely sometime after 30 minutes of work), so I do not know, how I could provide a testcase for this, sorry:(.
Comment 20 martin CLA 2011-03-07 14:17:01 EST
hi,
i tried to implement a simple maven project with some testng tests, but somehow I cannot reproduce this bug with a new project.
This is reproducable (not always, but surely sometime after 30 minutes of work), so I do not know, how I could provide a testcase for this, sorry:(.
Comment 21 Olivier Thomann CLA 2011-03-07 14:24:02 EST
(In reply to comment #20)
> This is reproducable (not always, but surely sometime after 30 minutes of
> work), so I do not know, how I could provide a testcase for this, sorry:(.
Would it be possible for me to get a hold onto the workspace that creates the problem ?
This seems to be the easiest way to fix this.
Comment 22 martin CLA 2011-03-07 14:38:54 EST
(In reply to comment #21)
> (In reply to comment #20)
> > This is reproducable (not always, but surely sometime after 30 minutes of
> > work), so I do not know, how I could provide a testcase for this, sorry:(.
> Would it be possible for me to get a hold onto the workspace that creates the
> problem ?
> This seems to be the easiest way to fix this.

Hi,

sorry, that is absolutely not possible, I'm really sorry, but I am not allowed to publish anything from my project:(.
Comment 23 Olivier Thomann CLA 2011-03-17 09:32:37 EDT
Closing as WORKSFORME.
Once you can provide a reproducable test case, I'll investigate.
Comment 24 Jay Arthanareeswaran CLA 2011-04-26 03:03:27 EDT
Verified for 3.7M7 using build I20110421-1800