Bug 122995 - [1.5][compiler] Access rules don't apply to generic types
Summary: [1.5][compiler] Access rules don't apply to generic types
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-06 22:08 EST by Matt McCutchen CLA
Modified: 2006-02-14 07:23 EST (History)
0 users

See Also:


Attachments
Patch that fixes the problem by checking restrictions on erased type (887 bytes, patch)
2006-01-06 22:11 EST, Matt McCutchen CLA
no flags Details | Diff
New patch includes fields and methods access detection and further tests. (22.36 KB, patch)
2006-01-13 06:32 EST, Maxime Daniel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt McCutchen CLA 2006-01-06 22:08:54 EST
My Eclipse: version 3.1.1, build id M20050929-0840

Library access rules set on a Java project's build bath don't seem to apply to certain uses of generic types.  The access rule checker seems to miss parameterized references to a generic type available as a class file and both parameterized and raw references to a generic type available in a source file.

To reproduce this, make a new Java project.  In its Build Path properties, go to Libraries -> JRE System Library -> Access Rules.  Add a Forbidden rule for java/util/** .  Now, put the following in Foo.java:

import java.util.*;

public class Foo {
	public static void main(String[] args) {
		Date d = new Date();
		HashSet<Integer> s = new HashSet<Integer>();
	}
}

The reference to Date will cause an error as it should, but the reference to HashSet goes unnoticed.

I have no prior experience with the innards of the Eclipse compiler, but I decided to debug Eclipse anyway, and I think I found the problem.  HashSet<Integer> is represented by a ParameterizedTypeBinding, which is correctly flagged as having restricted access (bit 18 in its modifiers).  However, this ParameterizedTypeBinding fails to match the BinaryTypeBinding for HashSet itself, on which the AccessRestriction is registered in the LookupEnvironment's accessRestrictions map.  Thus ASTNode.isTypeUseDeprecated fails to notice the restriction.

In my copy of Eclipse, I changed ASTNode.isTypeUseDeprecated to look up the erasure of the type instead of the type itself.  That seemed to fix the problem, but I don't know if it is the best fix.  I'm including a patch for the CVS version, even though I had trouble running the CVS version my computer.
Comment 1 Matt McCutchen CLA 2006-01-06 22:11:47 EST
Created attachment 32636 [details]
Patch that fixes the problem by checking restrictions on erased type
Comment 2 Maxime Daniel CLA 2006-01-11 10:08:08 EST
Reproduced with v_632, see AccessRestrictionsTests#test006.
Comment 3 Maxime Daniel CLA 2006-01-13 06:32:51 EST
Created attachment 32973 [details]
New patch includes fields and methods access detection and further tests.

Test cases:
- BatchCompilerTest 39
- AccessRestrictionsTests 6-10.
Comment 4 Maxime Daniel CLA 2006-01-13 06:44:03 EST
Verification: see initial post.
Comment 5 Philipe Mulet CLA 2006-01-17 04:19:28 EST
Pls backport fix to 3.1 maintenance stream.
Comment 6 Philipe Mulet CLA 2006-01-17 04:20:24 EST
Maxime: Also add corresponding entry for legal tracking:
Name: Matt McCutchen
Company:
Email: hashproduct@verizon.net
Business Address:
Business Phone:
Contribution:
        provided part of patch for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=122995 ([1.5][compiler] Access rules don't apply to generic types)
Title/Rights: EPL 1.0

in R3_1_maintenace version of the contributions file.
Comment 7 Matt McCutchen CLA 2006-01-17 14:05:59 EST
Do you really think I would sue for ten bytes?  :)
Comment 8 Maxime Daniel CLA 2006-01-18 08:49:27 EST
Backported into branch R3_1_maintenance.
Note that 76266 is not backported, hence only types are involved (neither fields nor methods).
Comment 9 Matt McCutchen CLA 2006-01-18 21:07:20 EST
I just remembered a related bug: References to generic types are also overlooked by the Plugin Manifest Editor's "Find unused dependencies" feature, which could lead a user to remove a plugin from the dependency list when a generic type from that plugin is actually being used.  I noticed this together with the access rule bug and just reproduced it using the same Eclipse as before: version 3.1.1, build id M20050929-0840.

Does the existing patch fix this problem?  I am still having trouble running the CVS version of Eclipse, so I have no way to tell.
Comment 10 Maxime Daniel CLA 2006-01-19 05:17:56 EST
(In reply to comment #9)
> Does the existing patch fix this problem?  I am still having trouble running
> the CVS version of Eclipse, so I have no way to tell.
No, I could reproduce it with HEAD (as of yesterday night). Please file a separate bug or let me know if you want me to do it.
Comment 11 Matt McCutchen CLA 2006-01-19 09:49:13 EST
I filed bug 124489 against the PDE for the misbehavior of "Find unused dependencies".  I thought the problem might be related to an underlying deficiency in Java search for references, in which case I would have filed it against the JDT, but this doesn't seem to be the case.
Comment 12 Jerome Lanneluc CLA 2006-02-14 07:23:37 EST
Verified for 3.2 M5 using build I20060214-0010