This is the mail archive of the
java-prs@sourceware.cygnus.com
mailing list for the Java project.
gcj/253: problems with instanceof when compilation from .class files
- To: java-gnats at sourceware dot cygnus dot com
- Subject: gcj/253: problems with instanceof when compilation from .class files
- From: warnes at biostat dot washington dot edu
- Date: 7 Jun 2000 05:06:26 -0000
- Reply-To: warnes at biostat dot washington dot edu
- Resent-Cc: java-prs at sourceware dot cygnus dot com, green at cygnus dot com
- Resent-Reply-To: java-gnats@sourceware.cygnus.com, warnes@biostat.washington.edu
>Number: 253
>Category: gcj
>Synopsis: problems with instanceof when compilation from .class files
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: apbianco
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jun 06 22:16:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator: Gregory Warnes <warnes@biostat.washington.edu>
>Release: current CVS
>Organization:
>Environment:
Linux 2.2.15
Debian Potato
Blackdown JDK 1.2.2 prelease 3 / IBM JDK 1.3 (prerelease)
>Description:
A instanceof B incorrectly returns false when B is an interface and A implements the interface.
This only seems to occur when 1) gcj was invoked on the .class files and 2) the class is passed to a function as a parameter of type B.
It does not occur if gcj was invoked on the raw .java files.
The follow three simple files illustrate the problem:
----------- source for test.java -----------
public class test
{
static public boolean doTest( InterfaceA ev )
{
if (ev instanceof ClassA )
return true;
else
return false;
}
static public void main( String[] argv )
{
InterfaceA de = new ClassA();
if( doTest(de) )
System.err.println("class correctly matched");
else
System.err.println("class incorrectly matched");
}
}
-------------- source for InterfaceA ---------------
public interface InterfaceA
{
}
-------------- source for ClassA ---------------
public class ClassA implements InterfaceA
{
public String field;
public ClassA()
{
field = "ClassA";
}
}
------------- Sample output -----------
> javac InterfaceA.java ClassA.java test.java
> gcj --main=test -o test InterfaceA.class ClassA.class test.class
> ./test
class incorrectly matched
> gcj --main=test -o test InterfaceA.java ClassA.java test.java
> ./test
class correctly matched
-------------- end of transcript ------------
The workaround appears to be to compile from the .java files rather than from the .class files. Unfortunately, my application makes use of inner classes, so I can't just use gcj with the raw .java files, so the work around is rather painful.
>How-To-Repeat:
>Fix:
Compile from .java rather than from .class .
>Release-Note:
>Audit-Trail:
>Unformatted: