United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4491755 (#129527 follow-up) Prob w/static inner class with same name as a regular class
JDK-4491755 : (#129527 follow-up) Prob w/static inner class with same name as a regular class

Details
Type:
Bug
Submit Date:
2001-08-14
Status:
Closed
Updated Date:
2003-04-12
Project Name:
JDK
Resolved Date:
2002-09-02
Component:
tools
OS:
solaris_8
Sub-Component:
javac
CPU:
sparc
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
1.4.2 (mantis)

Related Reports
Duplicate:
Relates:

Sub Tasks

Description

Name: bsC130419			Date: 08/14/2001


java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

Note that this is not a duplicate of 4489318 (Review ID: 129527).
That was a bug report against JDK1.3.1 and that bug is solved in 1.4beta,
this is a new one against 1.4beta with another test-case which exposes a very
similar bug.

When you have a class B which has a static inner class C and you have
another "normal" class C, this second class C can sometimes not be
found.

  To reproduce the problem:

mkdir bug
cd bug
mkdir src
mkdir src/x
mkdir src/y
mkdir classes

-------------------
-- src/x/B.java:
package x;

import x.*;

public class B {
    public static class C {}
}
-------------------
-- src/x/C.java:
package x;

import x.*;

public class C {}

-------------------
-- src/y/Main.java:
package y;

class Main {
        private R1 a;
        private R2 b;
        private R3 c;
}
-------------------
-- src/y/R1.java:
package y;

public final class R1 {
    x.B.C a = null;
    x.C b = null;
    R2 c = new R2();
}

---------------------
-- src/y/R2.java:
package y;

public final class R2 {
    x.B.C a = null;
    x.C b = null;
}

----------------------
-- src/y/R3.java
package y;

public final class R3 {
    x.B.C a = null;
    x.C b = null;
    R1 c = new R1();
}
-----------------------


Run the following, you will need to change the path to the compiler:
---------------------------------

#! /bin/sh -x

javac_cmd="/u/qmwanhj/j2sdk1.4.0/bin/javac -sourcepath .. -classpath
../../classes -d ../../classes -verbose"

rm -rf classes/*
(cd src/x; $javac_cmd B.java C.java)
echo
echo
(cd src/y; $javac_cmd Main.java)
echo
echo
sleep 1
# Here we modify the timestamp on R3.java to force a recompilation of
touch src/y/R3.java
sleep 1
echo
echo
# This compile fails.
(cd src/y; $javac_cmd Main.java)

---------------------------------------


You should get the following output:
javac_cmd=/u/qmwanhj/j2sdk1.4.0/bin/javac -sourcepath .. -classpath
../../classes -d ../../classes -verbose
+ rm -rf classes/x classes/y
+ cd src/x
+ /u/qmwanhj/j2sdk1.4.0/bin/javac -sourcepath .. -classpath ../../classes -d
../../classes -verbose B.java C.java
[parsing started B.java]
[parsing completed 328ms]
[parsing started C.java]
[parsing completed 2ms]
[checking x.B]
[loading /u/qmwanhj/j2sdk1.4.0/jre/lib/rt.jar(java/lang/Object.class)]
[wrote ../../classes/x/B$C.class]
[wrote ../../classes/x/B.class]
[checking x.C]
[wrote ../../classes/x/C.class]
[total 1277ms]
+ echo

+ echo

+ cd src/y
+ /u/qmwanhj/j2sdk1.4.0/bin/javac -sourcepath .. -classpath ../../classes -d
../../classes -verbose Main.java
[parsing started Main.java]
[parsing completed 345ms]
[loading /u/qmwanhj/j2sdk1.4.0/jre/lib/rt.jar(java/lang/Object.class)]
[loading ../y/R1.java]
[parsing started ../y/R1.java]
[parsing completed 4ms]
[loading ../../classes/x/B.class]
[loading ../../classes/x/B$C.class]
[loading ../../classes/x/C.class]
[loading ../y/R2.java]
[parsing started ../y/R2.java]
[parsing completed 3ms]
[loading ../y/R3.java]
[parsing started ../y/R3.java]
[parsing completed 3ms]
[checking y.Main]
[wrote ../../classes/y/Main.class]
[checking y.R1]
[wrote ../../classes/y/R1.class]
[checking y.R2]
[wrote ../../classes/y/R2.class]
[checking y.R3]
[wrote ../../classes/y/R3.class]
[total 1637ms]
+ echo

+ echo

+ sleep 1
+ touch src/y/R3.java
+ sleep 1
+ echo

+ echo

+ cd src/y
+ /u/qmwanhj/j2sdk1.4.0/bin/javac -sourcepath .. -classpath ../../classes -d
../../classes -verbose Main.java
[parsing started Main.java]
[parsing completed 345ms]
[loading /u/qmwanhj/j2sdk1.4.0/jre/lib/rt.jar(java/lang/Object.class)]
[loading ../../classes/y/R1.class]
[loading ../../classes/y/R2.class]
[loading ../y/R3.java]
[parsing started ../y/R3.java]
[parsing completed 7ms]
[loading ../../classes/x/B.class]
[loading ../../classes/x/B$C.class]
../y/R3.java:5: cannot resolve symbol
symbol  : class C
location: package x
    x.C b = null;
     ^
[checking y.Main]
[checking y.R3]
[total 1091ms]
1 error
(Review ID: 129966) 
======================================================================

                                    

Comments
PUBLIC COMMENTS

...
                                     
2004-06-10
EVALUATION

Looks like a bug.

Here's the script I used to reproduce it:

     1  #! /bin/sh
     2
     3  set -x
     4
     5  javac_cmd="newjavac -sourcepath src -classpath classes -d classes -verbose -prompt"
     6
     7  rm -rf classes/*
     8  $javac_cmd `find src -name \*.java -print`
     9  sleep 1
    10
    11  # Here we modify the timestamp on R3.java to force a recompilation of
    12  touch src/y/R3.java
    13
    14  # This compile fails.
    15  $javac_cmd src/y/Main.java

###@###.### 2001-08-16

==============================================

Another (perhaps simpler) test case from 4509039:

In the case when a top-level class and a static nested class, declared in
another class from the same packade, have the same name, Java compiler
jdk1.4.0beta3-b81 rejects or permits using of the top-level class
depending on the order of references to these same named classes.

To reproduce the bug compile 3 sources below:

> javac -d . Actions.java CallableSystemAction.java ToolbarButton.java

After that the compilation of bad.java in which the reference to class using
static nested class precedes the reference to top-level class reports an error.

> javac -d . bad.java
bad.java:7: cannot resolve symbol
symbol  : class ToolbarButton
location: package awt
        core.awt.ToolbarButton b;
                ^
1 error
>

Another source file in which the reference to the top-level class precedes the
reference to the class using static nested class is compiled successfully.

> javac -d . good.java
>

> java -version
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b81)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b81, mixed mode)


-----------------ToolbarButton.java------------------
package core.awt;

public class ToolbarButton  {
}
----------------------------------------------------
-----------------Actions.java------------------
package core.awt;

public class Actions {
        public static class ToolbarButton  {
        }
}
----------------------------------------------------
-----------------CallableSystemAction.java------------------
package core.util.actions;

import core.awt.*;

public class CallableSystemAction {
        Actions.ToolbarButton tb;
}
----------------------------------------------------
-----------------bad.java------------------
package t;

public class bad extends core.util.actions.CallableSystemAction {
}

class bad1 {
        core.awt.ToolbarButton b;
}
----------------------------------------------------
-----------------good.java------------------
package t;

class good1 {
        core.awt.ToolbarButton b;
}

public class good extends core.util.actions.CallableSystemAction {
}
----------------------------------------------------

======================================================================


                                     
2004-06-11
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mantis
mantis-b02

FIXED IN:
mantis
mantis-b02

INTEGRATED IN:
mantis
mantis-b02

VERIFIED IN:
mantis


                                     
2004-06-14



Hardware and Software, Engineered to Work Together