From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19228 invoked by alias); 9 Aug 2011 16:41:38 -0000 Received: (qmail 19212 invoked by uid 22791); 9 Aug 2011 16:41:37 -0000 X-SWARE-Spam-Status: No, hits=-0.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_GC X-Spam-Check-By: sourceware.org Received: from mail-gx0-f175.google.com (HELO mail-gx0-f175.google.com) (209.85.161.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 09 Aug 2011 16:41:23 +0000 Received: by gxk3 with SMTP id 3so134150gxk.20 for ; Tue, 09 Aug 2011 09:41:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.151.11.10 with SMTP id o10mr7433157ybi.171.1312908082618; Tue, 09 Aug 2011 09:41:22 -0700 (PDT) Received: by 10.147.82.10 with HTTP; Tue, 9 Aug 2011 09:41:22 -0700 (PDT) In-Reply-To: References: Date: Tue, 09 Aug 2011 17:29:00 -0000 Message-ID: Subject: Re: [PATCH] [JAVA] Double.parseDouble(null) throw NullPointerException From: Jie Liu To: Tom Tromey , java-patches@gcc.gnu.org, gcc-patches@gcc.gnu.org, Joel Sherrill Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact java-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-patches-owner@gcc.gnu.org X-SW-Source: 2011-q3/txt/msg00044.txt.bz2 Hi Tom, RTEMS does not have virtual memory management, so there is no error when access the 0 address on rtems. So 'str->length()' donot throw NPE and just return an meaningless value. Ps: There is a test: http://code.google.com/p/rtemsgcj/source/browse/trunk/algorithm/20110810NPE= /?r=3D127, npe.c is the main file and *.scn is the output. Thanks, Jie 2011/8/8 Tom Tromey : >>>>>> "Jie" =3D=3D Jie Liu writes: > > Jie> + =A0if(str =3D=3D NULL) > Jie> + =A0 =A0 =A0throw new NullPointerException(); > Jie> + > Jie> =A0 =A0int length =3D str->length(); > > Why doesn't 'str->length()' throw the NPE? > > Tom > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The first mail, for adding Joel =3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D Hi, When I use gcj on an RTOS(RTEMS), Double.parseDouble(null) throw NumberFormatException, but it should throw NullPointerException. So I add the patch below: Index: natVMDouble.cc =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- natVMDouble.cc (revision 172224) +++ natVMDouble.cc (working copy) @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -162,6 +163,9 @@ jdouble java::lang::VMDouble::parseDouble(jstring str) { + if(str =3D=3D NULL) + throw new NullPointerException(); + int length =3D str->length(); while (length > 0 The testsuite/Throw_2.java has been PASS after this patch. what do you think about this patch? Thanks, Jie