This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: [PATCH] [JAVA] Double.parseDouble(null) throw NullPointerException
- From: Jie Liu <lj8175 at gmail dot com>
- To: Tom Tromey <tromey at redhat dot com>, java-patches at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org, Joel Sherrill <joel dot sherrill at oarcorp dot com>
- Date: Wed, 10 Aug 2011 00:41:22 +0800
- Subject: Re: [PATCH] [JAVA] Double.parseDouble(null) throw NullPointerException
- References: <CABc96T_0THd_tKzdHSjD-xcPd7=dqoFkr0aRwrdvx-h4s2Hnxg@mail.gmail.com> <CABc96T_DNYxNsqKqdsVw7-x8uVc05_fB0BcHfJU5rv-VtFUv7A@mail.gmail.com> <m3zkjkugz9.fsf@fleche.redhat.com>
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=127,
npe.c is the main file and *.scn is the output.
Thanks,
Jie
2011/8/8 Tom Tromey <tromey@redhat.com>:
>>>>>> "Jie" == Jie Liu <lj8175@gmail.com> writes:
>
> Jie> + ?if(str == NULL)
> Jie> + ? ? ?throw new NullPointerException();
> Jie> +
> Jie> ? ?int length = str->length();
>
> Why doesn't 'str->length()' throw the NPE?
>
> Tom
>
=========== The first mail, for adding Joel ===========
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
===================================================================
--- natVMDouble.cc (revision 172224)
+++ natVMDouble.cc (working copy)
@@ -19,6 +19,7 @@
#include <java/lang/VMDouble.h>
#include <java/lang/Character.h>
#include <java/lang/NumberFormatException.h>
+#include <java/lang/NullPointerException.h>
#include <jvm.h>
#include <stdio.h>
@@ -162,6 +163,9 @@
jdouble
java::lang::VMDouble::parseDouble(jstring str)
{
+ if(str == NULL)
+ throw new NullPointerException();
+
int length = 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