public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* libgcj/5782: prims.cc produces null pointer while allocating an uninitialized object
@ 2002-02-25 19:56 toddastock
0 siblings, 0 replies; only message in thread
From: toddastock @ 2002-02-25 19:56 UTC (permalink / raw)
To: gcc-gnats
>Number: 5782
>Category: libgcj
>Synopsis: prims.cc null pointer while allocating an unitialized object.
>Confidential: no
>Severity: critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Feb 25 19:56:02 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:
>Release: 3.1 20020225 (experimental)
>Organization:
>Environment:
System: Linux escher 2.4.9-21 #1 Thu Jan 17 14:16:30 EST 2002 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure --enable-threads=posix --prefix=/home/tstock/local --disable-shared --enable-languages=c++,java : (reconfigured) : (reconfigured)
>Description:
In prims.cc it's possible to reach _Jv_AllocObjectNoFinalizer with class size equal to zero. Thus causing the _Jv_AllocObj to fail and throw a null pointer exception.
Nothing prior to the NestedCreater.create() call in the test case initializes the class TestDecl2 so the size is zero. It's initialized upon entering _Jv_AllocObjectNoFinalizer, but the size field is not re-read.
>How-To-Repeat:
File: Test.java:
========================================
import java.io.*;
import java.util.*;
import java.lang.reflect.*;
public class Test
{
static Class clz = null;
public static void main (String[] args)
{
Test t = new Test( );
try
{
clz = Class.forName( "TestDecl1" );
t.doit( clz );
}
catch( ClassNotFoundException e )
{
}
}
interface NestedCreator
{
public Object create(Object parent)
throws InvocationTargetException, IllegalAccessException, InstantiationException;
}
public void doit (final Class bean)
{
NestedCreator creator = null;
try
{
Method[] methods = bean.getMethods();
for( int i=0; i<methods.length; i++ )
{
final Method m = methods[i];
final String name = m.getName();
if( ! "dummy".equals(name) ) continue;
Class[] args = m.getParameterTypes();
final Constructor c = args[0].getConstructor(new Class[] {});
creator = new NestedCreator()
{
public Object create(Object parent)
throws InvocationTargetException, IllegalAccessException, InstantiationException
{
Object o = c.newInstance(new Object[] {});
m.invoke(parent, new Object[] {o});
return o;
}
};
}
}
catch( NoSuchMethodException nse )
{
}
try
{
// Throws NullPointerException
System.err.println("create="+creator.create( Test.clz.newInstance() ));
}
catch( IllegalAccessException e )
{
}
catch( InstantiationException e )
{
}
catch( InvocationTargetException e )
{
}
}
}
File: TestDecl1.java:
========================================
public class TestDecl1 extends TestDecl {
}
File: TestDecl2.java:
========================================
public class TestDecl2 extends TestDecl {
}
File: TestDecl.java:
========================================
public abstract class TestDecl {
public void dummy( TestDecl2 o )
{
System.err.println("dummy");
}
}
>Fix:
This may not be the appropriate fix for the problem. Possibly you would want to run _Jv_InitClass prior to entering the _Jv_AllocObjectNoFinalizer.
Index: prims.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.71
diff -u -r1.71 prims.cc
--- prims.cc 7 Feb 2002 18:59:50 -0000 1.71
+++ prims.cc 26 Feb 2002 03:00:17 -0000
@@ -381,6 +381,7 @@
_Jv_AllocObjectNoFinalizer (jclass klass, jint size)
{
_Jv_InitClass (klass);
+ if( size == 0 ) size = klass->size();
jobject obj = (jobject) _Jv_AllocObj (size, klass);
jvmpi_notify_alloc (klass, size, obj);
return obj;
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-02-26 3:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-25 19:56 libgcj/5782: prims.cc produces null pointer while allocating an uninitialized object toddastock
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).