Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 258917 - [jsr269] Not-yet-implemented methods in Java 6 APT
Summary: [jsr269] Not-yet-implemented methods in Java 6 APT
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: APT (show other bugs)
Version: 3.4.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.4.2   Edit
Assignee: Walter Harley CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 258915 (view as bug list)
Depends on: 259248 259249
Blocks:
  Show dependency tree
 
Reported: 2008-12-16 06:46 EST by Vladimir Piskarev CLA
Modified: 2009-01-14 12:04 EST (History)
4 users (show)

See Also:
philippe_mulet: pmc_approved+


Attachments
Draft patch (for discussion) (8.91 KB, patch)
2009-01-06 11:28 EST, Walter Harley CLA
no flags Details | Diff
Proposed fix (7.25 KB, patch)
2009-01-06 12:19 EST, Olivier Thomann CLA
no flags Details | Diff
New proposal (19.05 KB, patch)
2009-01-12 10:07 EST, Olivier Thomann CLA
no flags Details | Diff
Last proposal (19.22 KB, patch)
2009-01-12 13:25 EST, Olivier Thomann CLA
no flags Details | Diff
Same fix + one more regression test (20.27 KB, patch)
2009-01-12 13:37 EST, Olivier Thomann CLA
no flags Details | Diff
Corresponding patch for HEAD (20.18 KB, patch)
2009-01-12 13:51 EST, Olivier Thomann CLA
no flags Details | Diff
New patch that handles error cases (20.26 KB, patch)
2009-01-13 13:22 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Piskarev CLA 2008-12-16 06:46:32 EST
Build ID: M20080911-1700

At present, some methods in APT classes throw UnsupportedOperationException. It makes implementing APT processors harder than necessary.

- TypesImpl#isSubtype throws UOE for array types and reference types.
- VariableElementImpl#getEnclosingElement throws UOE for PARAMETER elements.
Comment 1 Vladimir Piskarev CLA 2008-12-16 06:47:21 EST
*** Bug 258915 has been marked as a duplicate of this bug. ***
Comment 2 Olivier Thomann CLA 2008-12-18 08:08:05 EST
Opened bug 259248 and 259249 for individual methods.
Comment 3 Walter Harley CLA 2008-12-19 02:21:28 EST
Assigning to myself for tracking - will close when the cloned bugs are fixed.
Comment 4 Walter Harley CLA 2009-01-06 11:28:06 EST
Created attachment 121644 [details]
Draft patch (for discussion)

Attaching a patch from Olivier, for discussion.  I suspect this patch is too invasive to get into 3.4.2, but I thought I would ask since it is affecting a user.

(This bug was cloned into two others, but since Olivier's patch addresses both it seems best to put the patch here.)

I have two concerns about this patch:

1. The patch adds a backpointer to the enclosing method for each parameter binding. APT needs to be able to retrieve the enclosing method having only a binding that corresponds to the parameter of the method.  In this draft patch, the backpointer is added to the LocalVariableBinding.  It is initialized only for APT, but it takes space for every parameter.  So this is not ideal.

Is it okay to do that?  An alternative might be to subclass the LocalVariableBinding and create an instance of this class based on the current LocalVariableBinding.

2. Is it correct that the erasure of a non-reference type is itself?  Does that correctly handle array types?  I'm looking at http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.6 and would expect it to return a type mirror for an array of the erasure of the leaf type.
Comment 5 Olivier Thomann CLA 2009-01-06 12:19:54 EST
Created attachment 121657 [details]
Proposed fix

New patch for erasure(), getEnclosingElement() and isSubType().
That patch should address the two concerns from comment 4.
Comment 6 Olivier Thomann CLA 2009-01-06 12:20:50 EST
Note that erasure() was not directly requested to be fixed, but since it is also missing implementation, it might be a good idea to get it right.
Comment 7 Walter Harley CLA 2009-01-07 01:56:18 EST
For me, when applied to 3.4 maintenance branch, this does not pass the tests in o.e.jdt.compiler.apt.tests.AllTests.  It fails on ModelTests.testElementWithEclipseCompiler, examining the declaration "public void methodDvoid(DEnum dEnum1) {}".  When it tries to get the enclosing element of dEnum1, the declaringScope of the LocalVariableBinding representing dEnum1 is null, instead of pointing to the method as expected.

In ExecutableElementImpl.getParameters(), line 137, the methodDeclaration we get does have a MethodScope; but in its argument list, the LocalVariableBinding's declaredScope is null, instead of pointing back to the MethodScope as I would expect.

As a side note, we'll also need to update the copyright dates of any files we touch, since it's now 2009.  I can take care of that, of course.
Comment 8 Olivier Thomann CLA 2009-01-08 10:05:01 EST
I'll double check again.
Comment 9 Olivier Thomann CLA 2009-01-12 10:07:41 EST
Created attachment 122269 [details]
New proposal

Walter,

Please try this one. Let me know if it works for you. I don't use the scope anymore, but I create an instance of a subclass of LocalVariableBinding to hold to the enclosing method.
Like this there is no impact on the compiler, and the impact should be minimal for apt.
Let me know what you think.
Comment 10 Olivier Thomann CLA 2009-01-12 10:08:12 EST
I think I also handle the binary case. Which was not the case with the previous patch.
Comment 11 Olivier Thomann CLA 2009-01-12 13:25:08 EST
Created attachment 122305 [details]
Last proposal

I forgot one case in the previous proposal.
This should now be fine.
Comment 12 Olivier Thomann CLA 2009-01-12 13:37:09 EST
Created attachment 122307 [details]
Same fix + one more regression test

Same patch as before with one more regression test for binary methods.
Comment 13 Walter Harley CLA 2009-01-12 13:48:59 EST
With that patch, the tests all pass for me.  

I was a little concerned about putting org.eclipse.jdt.internal.compiler.lookup types into the org.eclipse.jdt.compiler.apt plug-in because it adds confusion, but since this plug-in is actually just a fragment that separates the JSR269 types (many of which require Java 6) from the rest of the compiler I think I can convince myself it's okay.  If the types were in the compiler core plug-in, they would never get used or referenced except by the APT fragment, so that is probably even worse.

Vladimir, does this patch work for you?
Comment 14 Olivier Thomann CLA 2009-01-12 13:51:59 EST
Created attachment 122310 [details]
Corresponding patch for HEAD

With a slightly improved regression test for binary methods.
Comment 15 Walter Harley CLA 2009-01-12 14:00:27 EST
Tests pass in HEAD.  Committed to HEAD for 3.5M5.  I will request PMC approval to apply to 3.4.x.
Comment 16 Olivier Thomann CLA 2009-01-13 10:55:02 EST
We missed one last case when the argument has no binding because there is a compile error.
I'll update the patch for 3.4.x.

HEAD should be fixed now.
Comment 17 Walter Harley CLA 2009-01-13 11:26:13 EST
Hi, Olivier.  I am wondering whether the problem you found this morning means that maybe there are still some other problems lurking in the Visitor.  

It would be bad to introduce NPEs into the Visitor - I can deal with UOEs in particular API methods, because I can just tell people that those aren't implemented yet, but if we get NPEs in the Visitor it means that APT is broken depending on the code being processed, even if the processor doesn't call any particular methods.

How confident do you feel in the final version of the code?  Should we pull back, and not try to get the changes into 3.4.2?

(Reopening the bug for discussion, till we resolve this.)
Comment 18 Olivier Thomann CLA 2009-01-13 11:29:42 EST
Hi,

I am double-checking a last fix. Before we used to process method and arguments only when the argument had annotations.
So the fix was not good enough in error cases (compile errors, where some bindings (method or argument are null)).
I am working on it.
Comment 19 Olivier Thomann CLA 2009-01-13 13:22:51 EST
Created attachment 122438 [details]
New patch that handles error cases
Comment 20 Olivier Thomann CLA 2009-01-13 13:23:10 EST
That patch is already released in HEAD.
Comment 21 Walter Harley CLA 2009-01-13 21:39:56 EST
Requesting PMC approval to put this into 3.4.2.

I have reviewed Olivier's patch and tested it manually as well as with the automated tests, and it seems to cope with the error conditions (defective and unexpected code) that I threw at it.  Olivier is confident that the patch does not expose any new failures, that is, the AST visitor is not going to fail in situations where before it would have succeeded.  I therefore retract my concerns.

Thanks!
Comment 22 Philipe Mulet CLA 2009-01-14 05:52:23 EST
+1 for 3.4.2
Comment 23 Vladimir Piskarev CLA 2009-01-14 06:25:51 EST
(In reply to comment #13)
> 
> Vladimir, does this patch work for you?
> 

Walter, this patch seems to work for me. Thanks a lot!
Comment 24 Mike Wilson CLA 2009-01-14 09:16:30 EST
(In reply to comment #21)
> I have reviewed Olivier's patch ... I therefore retract my
> concerns.
> 

Thanks, Walter. I appreciate your diligence.

Comment 25 Walter Harley CLA 2009-01-14 12:04:56 EST
Fixed in 3.4.2.