Bug 106631 - Access rule has no effect
Summary: Access rule has no effect
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.2 RC3   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-10 10:45 EDT by Yen Lu CLA
Modified: 2006-05-04 11:12 EDT (History)
2 users (show)

See Also:


Attachments
Plugin projects (48.77 KB, application/octet-stream)
2005-08-10 10:54 EDT, Yen Lu CLA
no flags Details
Proposed fix (2.19 KB, patch)
2006-04-26 18:03 EDT, Olivier Thomann CLA
no flags Details | Diff
New patch (2.19 KB, patch)
2006-04-26 19:01 EDT, 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 Yen Lu CLA 2005-08-10 10:45:23 EDT
Consider the following relationship between 4 plugins:

u <- v <- w

where v depends on u and w depends on v

Also: v <- x and w <- x

In the u plugin, I define a base class:

package foo;

public class Base
{
  public u.MyObject execute() { return null; }
}

The MyObject class is just:

package u;

public class MyObject {}

The v plugin contains only the dependency on plugin u and no source code.

Plugin w contains a dependency on v and the following source:

package foo;

public class Base
{
  public w.MyObject execute() { return null; }
}

with:

package w;

public class MyObject {}

In x, there is one source file:

package x;

public class Derived extends foo.Base
{
  public w.MyObject execute() { return null; }
}

If you generate an ant build file for plugin x and execute it, you'll get:

       [mkdir] Created dir: F:\astk\eclipse\workspace\x\temp.folder\@dot.bin
       [javac] Compiling 1 source file to 
F:\astk\eclipse\workspace\x\temp.folder\@dot.bin
       [javac] ----------
       [javac] 1. ERROR in F:\astk\eclipse\workspace\x\src\x\Derived.java
       [javac]  (at line 7)
       [javac] 	public MyObject execute()
       [javac] 	                ^^^^^^^^^
       [javac] The return type is incompatible with Base.execute()
       [javac] ----------
       [javac] 1 problem (1 error)
       [javac] Compilation failed. Compiler errors are available in 
F:\astk\eclipse\workspace\x\temp.folder\@dot.bin.log
       [javac] Compile failed; see the compiler error output for details.
        [copy] Copying 1 file to F:\astk\eclipse\workspace\x\@dot
      [delete] Deleting directory 
F:\astk\eclipse\workspace\x\temp.folder\@dot.bin

Looking at build.xml, it creates the following <pathelement> entries for the
classpath:

				<pathelement path="../v/bin/"/>
				<pathelement path="../v/@dot"/>
				<pathelement path="../u/bin/"/>
				<pathelement path="../u/@dot"/>
				<pathelement path="../w/bin/"/>
				<pathelement path="../w/@dot"/>

This means that u's Base class is used to compile Derived rather than w's. This
is inconsistent with the workbench's behavior. Is there any reason why u even
needs to be on the classpath?

I will attach the plugin projects and the generated build.xml.
Comment 1 Yen Lu CLA 2005-08-10 10:54:41 EDT
Created attachment 25974 [details]
Plugin projects
Comment 2 Yen Lu CLA 2005-10-18 09:15:05 EDT
Is anyone going to look into this?
Comment 3 Pascal Rapicault CLA 2005-11-11 14:31:56 EST
u gets on x compile path because x requires v which requires u.
Deleting v from x or making w first on the prereq list would workaround the problem.

The more fundamental problem is that pde build does not realize that u does not
export classes and it does not use access rules.
Comment 4 Jeff McAffer CLA 2006-04-24 14:37:17 EDT
need to verify that this is fixed.
Comment 5 Andrew Niefer CLA 2006-04-26 14:10:09 EDT
I lowered the severity to normal since there is a simple workaround (reorder the dependencies so that w is before v)

In 3.2 PDE.Build now specifies access rules for the classpath.  (Regenerate the build.xml in x by doing PDE Tools->Create Ant Build File on the manifest). In this case we give Forbiden keep looking (?**/*) for the classpath elements from u, so the compiler should keep looking and find the classes from w which has an accessible rule.  

Even with the access rule we seem to still be getting the class from u, is this a problem with the batch compiler?
Comment 6 Yen Lu CLA 2006-04-26 14:13:18 EDT
I still feel this problem is major at the very least. The workaround cannot be
applied in our case since the dependencies are specified in third party code.
Comment 7 Olivier Thomann CLA 2006-04-26 14:24:43 EDT
I'll investigate it to narrow it down.
Comment 8 Olivier Thomann CLA 2006-04-26 15:04:29 EDT
The bug comes from the fact that the access rules are not passed to the batch compiler in this case.
Once I manually set the access rules on the classpath entries, it compiles fine. So the bug comes from the ant adapter.
I'll keep looking.
Philippe,

This might be a candidate for RC2.
Comment 9 Olivier Thomann CLA 2006-04-26 15:51:19 EDT
This is due to a mismatch between the path before the access rule in the @file on the classpath and the path inside the classpath.
When we get the classpath inside ant, the trailing '\' or '/' has been removed.
But inside the access rule file it is still there.
Therefore when we try to match the access rule with the right classpath entry using pathElements[i].endsWith(rules[j]), it never matches.
And we end up setting no access rules at all.

path element = D:\eclipse\workspaces\test106631\v\bin
Current rule = v\bin\
Current rule = v\@dot
Current rule = u\bin\
Current rule = u\@dot
Current rule = w\bin\
Current rule = w\@dot

The same for other entries.

Andrew, we have to make sure that both pathes are consistent.
Can you talk about this tomorrow ?
Comment 10 Olivier Thomann CLA 2006-04-26 18:02:13 EDT
I believe the fix should go inside the ant adapter since PDE cannot rely on what is done by ant or not.
PDE provides consistent information to the ant javac task, but before the ant adatper is called the trailing slashes inside the folder names are removed by ant.

The matching inside the ant adapter to match the rules with the classpath entries must be resilient to this kind of modifications.

I propose a patch that checks if rule ends with File.separator and if the pathElement ends with File.separator. Both checks need to be done because we cannot make any assumption on the last character of the rule or the path element.
Comment 11 Olivier Thomann CLA 2006-04-26 18:03:06 EDT
Created attachment 39607 [details]
Proposed fix

With this patch, the given test compiles fine.
Andrew,

Could you please review it?
Comment 12 Andrew Niefer CLA 2006-04-26 18:40:09 EDT
I took a look, and the only thing I see is that I think the comparison should be case-sensitive and you have ignoreCase=true in the regionMatches calls.  I will do some more tests tomorrow.
Comment 13 Olivier Thomann CLA 2006-04-26 19:01:26 EDT
Created attachment 39611 [details]
New patch

New patch case sensitive
Comment 14 Andrew Niefer CLA 2006-04-27 11:18:36 EDT
+1.  New patch is good, I haven't found any other problems.
Comment 15 Jeff McAffer CLA 2006-04-27 11:58:34 EDT
+1 for release in RC3
Comment 16 Philipe Mulet CLA 2006-04-27 12:47:51 EDT
+1 for 3.2RC3
Comment 17 Olivier Thomann CLA 2006-05-01 09:49:02 EDT
Sonia got a patch to run a test build with this fix.
Comment 18 Olivier Thomann CLA 2006-05-02 09:13:12 EDT
Test build was successful.
Fixed and released in HEAD.
Comment 19 Olivier Thomann CLA 2006-05-02 09:16:11 EDT
In order to verify, please use the attached test case.
Comment 20 Olivier Thomann CLA 2006-05-03 10:39:30 EDT
Verified using N20060503-0010 for 3.2RC3
Comment 21 Frederic Fusier CLA 2006-05-04 11:12:36 EDT
Double-checked using N20060504-0010 + JDT/Core v_663