Bug 170197 - [model] JavaCore.newLibraryEntry(.., IClasspathAttribute[], ..) should check for null
Summary: [model] JavaCore.newLibraryEntry(.., IClasspathAttribute[], ..) should check ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 RC1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-11 05:53 EST by Markus Keller CLA
Modified: 2009-05-15 04:00 EDT (History)
5 users (show)

See Also:


Attachments
Proposed patch + tests (10.43 KB, patch)
2009-05-08 04:21 EDT, Srikanth Sankaran CLA
no flags Details | Diff
Revised patch (7.33 KB, patch)
2009-05-12 06:11 EDT, Srikanth Sankaran CLA
jerome_lanneluc: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2007-01-11 05:53:16 EST
I20070109-1805

JavaCore.newLibraryEntry(.., IClasspathAttribute[], ..) should throw an exception if the given IClasspathAttribute[] is not null. Currently, null is silently accepted and leads to NPEs when the extra attributes are accessed later.

Although unspecified, passing null for accessRules is currently accepted (and explicitly handled). Therefore, it's maybe better to continue allowing null for accessRules. Even jdt.core code currently relies on this behavior, see ClasspathEntry.decodeAccessRules(NodeList).

I just fixed a broken invocation in our class BuildPathSupport, but such problems may be hard to find in general since creation and usage are quite separated.
Comment 1 Jerome Lanneluc CLA 2007-06-19 10:55:50 EDT
I guess you meant that it should throw an exception if the extraAttributes argument is null.

To be investigated for 3.4.
Comment 2 Markus Keller CLA 2007-06-19 12:25:50 EDT
> I guess you meant that it should throw an exception if the extraAttributes
> argument is null.
Yes, sorry about that.

You should actually fix this for all 5 callers of the ClasspathEntry constructor in JavaCore. And for the accessRules parameter, you should either explicitly allow null in the Javadoc or throw an exception as well.
Comment 3 Jerome Lanneluc CLA 2008-05-07 12:32:44 EDT
Deferring post 3.4
Comment 4 Jerome Lanneluc CLA 2009-02-10 07:17:13 EST
This one should be trivial. I think IllegalArgumentException should be thrown if null is being passed and this is specified in the Javadoc.
Comment 5 Srikanth Sankaran CLA 2009-05-04 06:59:39 EDT
(In reply to comment #4)
> This one should be trivial. I think IllegalArgumentException should be thrown
> if null is being passed and this is specified in the Javadoc.

It would appear more consistent to throw 
ClasspathEntry#AssertionFailedException as is done by
org.eclipse.jdt.core.JavaCore.newSourceEntry(IPath, IPath[], IPath[], IPath, IClasspathAttribute[]) ?



Comment 6 Srikanth Sankaran CLA 2009-05-04 07:01:12 EDT
Jerome, comment#5 was addressed to you for input.
Comment 7 Jerome Lanneluc CLA 2009-05-04 08:59:19 EDT
(In reply to comment #6)
> Jerome, comment#5 was addressed to you for input.
> 
Yes, using ClasspathEntry#AssertionFailedException makes sense
Comment 8 Srikanth Sankaran CLA 2009-05-08 04:21:47 EDT
Created attachment 134940 [details]
Proposed patch + tests

Jerome, please review.
Comment 9 Jerome Lanneluc CLA 2009-05-11 05:19:28 EDT
After more thought, I'm wondering why we would not allow extraAttributes to be null and consider that this is the same as an empty list. This would be more consistent with the fact that accessRules can also be null. So in both cases, we could specify that null is accepted and fix the implementation for extraAttributes. Any thought?
Comment 10 Markus Keller CLA 2009-05-11 06:05:36 EDT
> After more thought, I'm wondering why we would not allow extraAttributes to be
> null and consider that this is the same as an empty list.

Would also be fine for me, but then I would do this for all parameters that accept an empty array (i.e. also for inclusionPatterns and exclusionPatterns).
Comment 11 Srikanth Sankaran CLA 2009-05-12 06:11:58 EDT
Created attachment 135317 [details]
Revised patch

Jerome, please review, thanks.
Comment 12 Srikanth Sankaran CLA 2009-05-12 06:22:21 EDT
(In reply to comment #11)
> Created an attachment (id=135317) [details]
> Revised patch
> Jerome, please review, thanks.

BTW, this patch would "allow extraAttributes to be null and consider
that this is the same as an empty list". 

Likewise for accessRules, inclusionPatterns and exclusionPatterns.

I left the javadoc as it is: i.e did not update it to say "empty list
or null.". There are many more methods whose javadoc would have to be
updated than are involved in the code change and I didn't see the value
in the exercise. (the real value being not allowing null references to
be propagated and captured in the state associated with ClasspathEntry,
thereby leading to an NPE downstream resulting in problems that "may be
hard to find in general since creation and usage are quite separated."
per comment #0 - this is accomplished by the code change)


Comment 13 Jerome Lanneluc CLA 2009-05-14 05:00:59 EDT
Comment on attachment 135317 [details]
Revised patch

Patch looks good
Comment 14 Srikanth Sankaran CLA 2009-05-14 06:13:30 EDT
Released in HEAD for 3.5 RC1
Comment 15 David Audel CLA 2009-05-15 04:00:03 EDT
Verified for 3.5RC1 using I20090514-2000