United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6198196 package-info.java: Weird compiler error
JDK-6198196 : package-info.java: Weird compiler error

Details
Type:
Bug
Submit Date:
2004-11-20
Status:
Closed
Updated Date:
2010-12-02
Project Name:
JDK
Resolved Date:
2005-06-08
Component:
tools
OS:
windows_xp
Sub-Component:
javac
CPU:
generic
Priority:
P1
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Relates:
Relates:
Relates:

Sub Tasks

Description
Compiling package-info.java gives this error:

E:/ws/hostd/bora/vim/vmodl/vim/host/package-info.java:4: package annotations
should be in file package-info.java
@wsdlName("Host") package vim.host;

The file looks like this:

   @wsdlName("Host") package vim.host;
   import vmodl.*;

Addtional info from submitter:

I was able to reproduce the problem on WindowsXP using your files.

My command line was:
         javac C:/home/pcanning/wsdlName.java 
C:/home/pcanning/package-info.java
It is important that the slashes be forward slashes not backward slashes.
If I do
         javac C:\home\pcanning\wsdlName.java 
C:\home\pcanning\package-info.java
or
         javac wsdlName.java package-info.java
I don't get the error.

--- package-info.java ---
@wsdlName("Host") package vim.host;
import vmodl.*;

--- wsdlName.java ---
package vmodl;
public @interface wsdlName { String value(); }



                                    

Comments
EVALUATION

I need a reproducible test case.

###@###.### 2004-11-20 00:43:05 GMT

Based on the additional information from the submitter I was able to
reproduce the problem on Windows XP.  You need to run it from the
Windows command prompt, cygwin is too helpful.

I cannot create a regression test as I don't have a way to test platform
specific behavior.

###@###.### 2004-11-25 02:08:04 GMT

SQE (###@###.###) will implement tests for this.

###@###.### 2004-11-29 18:38:15 GMT

I turns out that it is easy to write test for platform specific
behavior in jtreg, so SQE doesn't need to write a test case.

###@###.### 2005-05-27 23:03:53 GMT
                                     
2004-11-20
SUGGESTED FIX

Index: src/share/classes/com/sun/tools/javac/comp/Enter.java
============================================================
@@ -369,28 +368,23 @@
 	 */
 	private static boolean classNameMatchesFileName(ClassSymbol c,
 							Env<AttrContext> env) {
-	    // XXX 06/09/99 iris
-	    // Using a Name for filename is a small abuse of the abstraction.
 	    String fname = env.toplevel.sourcefile.toString();
 	    String cname = c.name + ".java";
-	    try {
-		return
-		    endsWith(fname, cname)
-		    // hack to make things work for Windows 95:
-		    || endsWith(new File(fname).getCanonicalPath(), cname);
-	    } catch (java.io.IOException ex) {
-		return false;
-	    }
+	    return endsWith(fname, cname);
 	}
 	//where
 	    /** Does path name have file name as last component?
 	     */
 	    protected static boolean endsWith(String pathname, String filename) {
-		return
-		    pathname.endsWith(filename) &&
-		    (pathname.length() == filename.length() ||
-		     pathname.charAt(pathname.length() - filename.length() - 1) ==
-		     File.separatorChar);
+		if (pathname.endsWith(filename)) {
+		    int diff = pathname.length() - filename.length();
+		    if (diff == 0 || pathname.charAt(diff - 1) == File.separatorChar)
+			return true;
+		    File path = new File(new File(pathname).getName());
+		    File file = new File(filename);
+		    return path.equals(file);
+		}
+		return false;
 	    }
 
     /** Complain about a duplicate class. */

###@###.### 2004-11-25 04:15:43 GMT
                                     
2004-11-25
WORK AROUND

Use cygwin or don't use forward slashes on Windows.

###@###.### 2004-11-25 02:16:06 GMT
                                     
2004-11-25



Hardware and Software, Engineered to Work Together