Bug 45459 - JDT compiler more restrictive than javac
Summary: JDT compiler more restrictive than javac
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC All
: P2 major (vote)
Target Milestone: 3.0 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-23 13:56 EDT by Dejan Glozic CLA
Modified: 2003-10-24 15:17 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dejan Glozic CLA 2003-10-23 13:56:49 EDT
Here is the scenario that is causing problems to PDE when self-hosting against 
OSGi runtime:

1) Take M4 build
2) Download OSGi runtime from Equinox home page (build 1010) and unzip on top 
of the build
3) Start another Eclipse driver (not this one) with a clean workspace. 
Configure it so that PDE->Target Platform points at the M4 OSGi build created 
in 2).
4) Import all the external plug-ins and fragments as binary projects into the 
workspace.
5) Create 'Hello, World' plug-in using PDE 'New Plug-in project' wizard. Keep 
all the defaults.

Notice that the build fails with the following error in XyzPlugin.java:

The type org.osgi.framework.Bundle cannot be resolved. It is indirectly 
referenced from required .class files.	XyzPlugin.java

XyzPlugin does not reference Bundle type directly anywhere. However, it does 
extend AbstractUIPlugin, which in turn extends Plugin (provided by 
org.eclipse.runtime.compatibility) and this class has 'Bundle getBundle()' 
method, as well as Bundle private field.

As suggested, I went into the workspace from the OS shell and tried to compile 
XYZPlugin using javac.exe. I managed to get it to compile without having to 
put org.eclipse.osgi.framework.core plug-in on the classpath (this is where 
Bundle type is declared).

It seems to me that JDT compiler is too eager when resolving Plugin class. It 
should not need to resolve Bundle reference since it was never used explicitly 
in XyzPlugin class itself.
Comment 1 Philipe Mulet CLA 2003-10-24 05:29:51 EDT
We used to be resolving too much, and thus finding inconsistencies which we 
should have been ignoring. We added more laziness, but apparently we are still 
unoptimal.

Must fix.
Comment 2 Philipe Mulet CLA 2003-10-24 07:03:44 EDT
Reproduced with command-line:

@echo off
set CP00=d:\jdk1.4.2\jre\lib\rt.jar
set CP01=org.eclipse.core.boot\boot.jar
set CP02=org.eclipse.core.resources\resources.jar
set CP03=org.eclipse.core.runtime\runtime.jar
set CP04=org.eclipse.core.runtime.osgi\runtime.jar
set CP05=org.eclipse.core.runtime.compatibility\compatibility.jar
set CP06=org.eclipse.update.configurator\configurator.jar
set CP07=org.eclipse.core.runtime\runtime.jar
set CP08=org.apache.xerces\xmlParserAPIs.jar
set CP09=org.apache.xerces\xercesImpl.jar
set CP10=org.eclipse.ui\ui.jar
set CP11=org.eclipse.update.core\updatecore.jar
set CP12=org.eclipse.help\help.jar
set CP13=org.eclipse.help.url\url.jar
set CP14=org.eclipse.help.appserver\appserver.jar
set CP15=org.apache.lucene\parser.jar
set CP16=org.apache.lucene\lucene-1.3-rc1.jar
set CP17=org.eclipse.swt.win32\ws\win32\swt.jar
set CP18=org.eclipse.text\text.jar
set CP19=org.eclipse.jface\jface.jar
set CP20=org.eclipse.jface.text\jfacetext.jar
set CP21=org.eclipse.ui.views\views.jar
set CP22=org.eclipse.ui.workbench\workbench.jar
set CP23=org.eclipse.ui.win32\workbenchwin32.jar
set CP24=org.eclipse.ui.workbench.texteditor\texteditor.jar
set CP25=org.eclipse.ui.editors\editors.jar
set CP26=org.eclipse.core.filebuffers\filebuffers.jar

CD \eclipse\testing\equinox\plugins 
javac -verbose -classpath %CP00%;%CP01%;%CP02%;%CP03%;%CP04%;%CP05%;%CP06%;%
CP07%;%CP08%;%CP09%;%CP10%;%CP11%;%CP12%;%CP13%;%CP14%;%CP15%;%CP16%;%CP17%;%
CP18%;%CP19%;%CP20%;%CP21%;%CP22%;%CP23%;%CP24%;%CP25%;%CP26% -d 
d:\eclipse\workspaces\dev3.0\plugins\Crap\bin\ 
D:\eclipse\testing\equinox\plugins\HelloWorld\src\HelloWorld\HelloWorldPlugin.ja
va
CD \

Comment 3 Philipe Mulet CLA 2003-10-24 07:04:56 EDT
Interestingly, jikes 1.18 will also refuse to compile:
Found 6 semantic errors 
compiling "D:/eclipse/testing/equinox/plugins/HelloWorld/src/HelloWorld/Hell
oWorldPlugin.java":

    11. public class HelloWorldPlugin extends AbstractUIPlugin {
                     ^--------------^
*** Semantic Error: You need to modify your classpath, sourcepath, 
bootclasspath, and/or extdirs set
up. Package "org/osgi/framework" could not be found in:
                d:\jdk1.4.2\jre\lib\rt.jar
                org.eclipse.core.boot\boot.jar
                org.eclipse.core.resources\resources.jar
                org.eclipse.core.runtime\runtime.jar
                org.eclipse.core.runtime.osgi\runtime.jar
                org.eclipse.core.runtime.compatibility\compatibility.jar
                org.eclipse.update.configurator\configurator.jar
                org.apache.xerces\xmlParserAPIs.jar
                org.apache.xerces\xercesImpl.jar
                org.eclipse.ui\ui.jar
                org.eclipse.update.core\updatecore.jar
                org.eclipse.help\help.jar
                org.eclipse.help.url\url.jar
                org.eclipse.help.appserver\appserver.jar
                org.apache.lucene\parser.jar
                org.apache.lucene\lucene-1.3-rc1.jar
                org.eclipse.swt.win32\ws\win32\swt.jar
                org.eclipse.text\text.jar
                org.eclipse.jface\jface.jar
                org.eclipse.jface.text\jfacetext.jar
                org.eclipse.ui.views\views.jar
                org.eclipse.ui.workbench\workbench.jar
                org.eclipse.ui.win32\workbenchwin32.jar
                org.eclipse.ui.workbench.texteditor\texteditor.jar
                org.eclipse.ui.editors\editors.jar
                org.eclipse.core.filebuffers\filebuffers.jar
                .



    11. public class HelloWorldPlugin extends AbstractUIPlugin {
                     ^--------------^
*** Semantic Error: Type org.osgi.framework.BundleActivator was not found.


    11. public class HelloWorldPlugin extends AbstractUIPlugin {
                     ^--------------^
*** Semantic Error: You need to modify your classpath, sourcepath, 
bootclasspath, and/or extdirs set
up. Package "org/osgi/framework" could not be found in:
                d:\jdk1.4.2\jre\lib\rt.jar
                org.eclipse.core.boot\boot.jar
                org.eclipse.core.resources\resources.jar
                org.eclipse.core.runtime\runtime.jar
                org.eclipse.core.runtime.osgi\runtime.jar
                org.eclipse.core.runtime.compatibility\compatibility.jar
                org.eclipse.update.configurator\configurator.jar
                org.apache.xerces\xmlParserAPIs.jar
                org.apache.xerces\xercesImpl.jar
                org.eclipse.ui\ui.jar
                org.eclipse.update.core\updatecore.jar
                org.eclipse.help\help.jar
                org.eclipse.help.url\url.jar
                org.eclipse.help.appserver\appserver.jar
                org.apache.lucene\parser.jar
                org.apache.lucene\lucene-1.3-rc1.jar
                org.eclipse.swt.win32\ws\win32\swt.jar
                org.eclipse.text\text.jar
                org.eclipse.jface\jface.jar
                org.eclipse.jface.text\jfacetext.jar
                org.eclipse.ui.views\views.jar
                org.eclipse.ui.workbench\workbench.jar
                org.eclipse.ui.win32\workbenchwin32.jar
                org.eclipse.ui.workbench.texteditor\texteditor.jar
                org.eclipse.ui.editors\editors.jar
                org.eclipse.core.filebuffers\filebuffers.jar
                .



    11. public class HelloWorldPlugin extends AbstractUIPlugin {
                     ^--------------^
*** Semantic Error: Type org.osgi.framework.Bundle was not found.


    11. public class HelloWorldPlugin extends AbstractUIPlugin {
                     ^--------------^
*** Semantic Error: You need to modify your classpath, sourcepath, 
bootclasspath, and/or extdirs set
up. Package "org/osgi/framework" could not be found in:
                d:\jdk1.4.2\jre\lib\rt.jar
                org.eclipse.core.boot\boot.jar
                org.eclipse.core.resources\resources.jar
                org.eclipse.core.runtime\runtime.jar
                org.eclipse.core.runtime.osgi\runtime.jar
                org.eclipse.core.runtime.compatibility\compatibility.jar
                org.eclipse.update.configurator\configurator.jar
                org.apache.xerces\xmlParserAPIs.jar
                org.apache.xerces\xercesImpl.jar
                org.eclipse.ui\ui.jar
                org.eclipse.update.core\updatecore.jar
                org.eclipse.help\help.jar
                org.eclipse.help.url\url.jar
                org.eclipse.help.appserver\appserver.jar
                org.apache.lucene\parser.jar
                org.apache.lucene\lucene-1.3-rc1.jar
                org.eclipse.swt.win32\ws\win32\swt.jar
                org.eclipse.text\text.jar
                org.eclipse.jface\jface.jar
                org.eclipse.jface.text\jfacetext.jar
                org.eclipse.ui.views\views.jar
                org.eclipse.ui.workbench\workbench.jar
                org.eclipse.ui.win32\workbenchwin32.jar
                org.eclipse.ui.workbench.texteditor\texteditor.jar
                org.eclipse.ui.editors\editors.jar
                org.eclipse.core.filebuffers\filebuffers.jar
                .



    11. public class HelloWorldPlugin extends AbstractUIPlugin {
                     ^--------------^
*** Semantic Error: Type org.osgi.framework.BundleContext was not found.
Comment 4 Philipe Mulet CLA 2003-10-24 07:06:27 EDT
We signal:
----------
1. ERROR in 
D:\eclipse\testing\equinox\plugins\HelloWorld\src\HelloWorld\HelloWorldPlugin.ja
va (at line 0)
        package HelloWorld;
        ^
The type org.osgi.framework.Bundle cannot be resolved. It is indirectly 
referenced from required .class files.
----------
Comment 5 Philipe Mulet CLA 2003-10-24 07:08:41 EDT
Reproducing with Java app invoking batch compiler:

import org.eclipse.jdt.internal.compiler.batch.Main;

public class Compile2 { 

    public static void main(String[] args) {
    	
    	String workspace = "D:/eclipse/testing/equinox/plugins/";

    	StringBuffer commandLine = new StringBuffer(30);
    	commandLine.append(" -1.4 -preserveAllLocals -proceedOnError -time -
verbose ");

    	commandLine.append(workspace).append
("HelloWorld/src/HelloWorld/HelloWorldPlugin.java");
    	
    	commandLine.append(" -cp ").append(" d:/jdk1.4.2/jre/lib/rt.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.core.boot/boot.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.core.resources/resources.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.core.runtime/runtime.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.core.runtime.osgi/runtime.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.core.runtime.compatibility/compatibility.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.update.configurator/configurator.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.core.runtime/runtime.jar");
    	commandLine.append(";").append(workspace).append
("org.apache.xerces/xmlParserAPIs.jar");
    	commandLine.append(";").append(workspace).append
("org.apache.xerces/xercesImpl.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.ui/ui.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.update.core/updatecore.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.help/help.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.help.url/url.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.help.appserver/appserver.jar");
    	commandLine.append(";").append(workspace).append
("org.apache.lucene/parser.jar");
    	commandLine.append(";").append(workspace).append
("org.apache.lucene/lucene-1.3-rc1.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.swt.win32/ws/win32/swt.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.text/text.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.jface/jface.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.jface.text/jfacetext.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.ui.views/views.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.ui.workbench/workbench.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.ui.win32/workbenchwin32.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.ui.workbench.texteditor/texteditor.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.ui.editors/editors.jar");
    	commandLine.append(";").append(workspace).append
("org.eclipse.core.filebuffers/filebuffers.jar");
    	
    	commandLine.append(" -d 
d:/eclipse/workspaces/dev3.0/plugins/Crap/bin/");
    	
    	System.out.println(commandLine.toString());
    	
    	Main.compile(commandLine.toString());
    }
}
Comment 6 Philipe Mulet CLA 2003-10-24 07:15:35 EDT
Problem comes from a compiler check for local variable hiding a field:

	public static String getResourceString(String key) {
>>>>>>>>	ResourceBundle bundle = HelloWorldPlugin.getDefault
().getResourceBundle();
		try {
			return (bundle!=null ? bundle.getString(key) : key);
		} catch (MissingResourceException e) {
			return key;
		}
	}

If renaming bundle, into bundle2, then the problem goes away.
Comment 7 Philipe Mulet CLA 2003-10-24 07:23:48 EDT
The hiding diagnosis finds the inherited Plugin slot:

private org.osgi.framework.Bundle bundle;		
Comment 8 Philipe Mulet CLA 2003-10-24 07:53:22 EDT
Changing hiding check to avoid resolving overriden match.
Comment 9 Dejan Glozic CLA 2003-10-24 10:16:48 EDT
Raising severity because this is blocking further progress on PDE support for 
pure OSGi bundle development against OSGi builds.
Comment 10 Philipe Mulet CLA 2003-10-24 10:24:12 EDT
For now, as a simple workaround, you may simply rename the Plugin#bundle slot:

private org.osgi.framework.Bundle bundle;
Comment 11 Philipe Mulet CLA 2003-10-24 10:25:39 EDT
I am testing a fix at the moment, will likely post it as a patch once test runs 
are ok (our compiler tests, jck1.3a, jck1.4a, jacks). If all goes well, patch 
should be available within today.
Comment 12 Philipe Mulet CLA 2003-10-24 10:38:08 EDT
Fixed. Introduced flag to avoid resolving fields in case trying to find pre-
existing variable (when checking for hiding scenario).
Comment 13 Philipe Mulet CLA 2003-10-24 11:32:30 EDT
Patch is available at:
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/jdt-core-
home/r3.0/main.html#updates
Comment 14 Dejan Glozic CLA 2003-10-24 12:20:35 EDT
Verified that the patch solves the problem. Thanks!
Comment 15 Philipe Mulet CLA 2003-10-24 15:17:12 EDT
Glad it works. Thanks for the accurate testcase.