This is the mail archive of the java-prs@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcj/253: problems with instanceof when compilation from .class files



>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:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]