From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32192 invoked by alias); 1 Aug 2005 15:50:43 -0000 Mailing-List: contact java-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-prs-owner@gcc.gnu.org Received: (qmail 32176 invoked by uid 48); 1 Aug 2005 15:50:43 -0000 Date: Mon, 01 Aug 2005 15:50:00 -0000 From: "hannes at helma dot at" To: java-prs@gcc.gnu.org Message-ID: <20050801155040.23182.hannes@helma.at> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug libgcj/23182] New: instanceof sometimes fails if compiled with -findirect-dispatch X-Bugzilla-Reason: CC X-SW-Source: 2005-q3/txt/msg00162.txt.bz2 List-Id: I'm compiling Rhino 1.5R5 with the following command: gcj --main=org.mozilla.javascript.tools.shell.Main -findirect-dispatch js.jar -o rhino The resulting Rhino JavaScript shell throws exceptions on some String functions: js> "foo".charAt(0); js: "", line 1: Primitive type expected (had java.lang.String instead) The code that throws the exception is in class src/org/mozilla/javascript/ScriptRuntime.java, static method toString(Object) at line 522: public static String toString(Object val) { for (;;) { if (val == null) return "null"; if (val instanceof Scriptable) { val = ((Scriptable) val).getDefaultValue(StringClass); if (val != Undefined.instance && val instanceof Scriptable) { throw errorWithClassName("msg.primitive.expected", val); } continue; } ... The val argument first refers to an instance of org.mozilla.javascript.NativeString, so instanceof Scriptable rightly evaluates to true. However, after the assignment val refers to an instance of java.lang.String, yet the second instanceof Scriptable still evaluates to true, and the exception is thrown. The String class actually looks ok (i.e. it doesn't contain Scriptable in the array returned by Class.getInterfaces(), so I guess this might be a caching bug in the implementation of instanceof. This only happens if the code is compiled with -findirect-dispatch. It still exists in gcj (GCC) 4.0.1 20050701 (prerelease), so chances are it is still present in the final 4.0.1 release. -- Summary: instanceof sometimes fails if compiled with -findirect- dispatch Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: libgcj AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: hannes at helma dot at CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu dot org GCC host triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23182