This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: Passing #!null as <java.lang.String>
- To: bmd at cs dot nwu dot edu (Brian M. Dennis)
- Subject: Re: Passing #!null as <java.lang.String>
- From: Per Bothner <per at bothner dot com>
- Date: 05 Sep 2001 08:33:06 -0700
- Cc: kawa at sources dot redhat dot com
- References: <m2bskpn898.fsf@colombia.cs.northwestern.edu>
bmd@cs.nwu.edu (Brian M. Dennis) writes:
> I have a feeling this is obviously documented somewhere, but can't
> seem to define the answer. What's the idiom for passing a #!null to a Java
> procedure where the argument is of type java.lang.String? Kawa seems to
> attempt to do a conversion and winds up null pointer dereferencing. e.g
>
> #|kawa:1|# (as <java.lang.String> #!null)
> java.lang.NullPointerException
Well, it is documented in the "Standard Types" section of the manual.
Unfortunately, there is a bug. Kawa is documented as distinguishing
between <java.lang.String> (acts like normal classes) and <String>
(uses toString for coercions). In fact, it ends up using the same
ClassType object for both.
I'm surprised this bug wasn't caught earlier!
The following patch should fix it.
Index: Type.java
===================================================================
RCS file: /cvs/kawa/kawa/gnu/bytecode/Type.java,v
retrieving revision 1.31
diff -u -r1.31 Type.java
--- Type.java 2001/08/24 00:04:22 1.31
+++ Type.java 2001/09/05 15:22:56
@@ -425,8 +425,11 @@
/** The magic type of null. */
public static final ObjectType nullType = new ObjectType("(type of null)");
+ /* The String type. but coercion is handled by toString. */
+ static public ClassType string_type = new ClassType("java.lang.String");
+ static { string_type.flags |= ClassType.EXISTING_CLASS; }
+
static public ClassType pointer_type = ClassType.make("java.lang.Object");
- static public ClassType string_type = ClassType.make("java.lang.String");
static public ClassType boolean_ctype = ClassType.make("java.lang.Boolean");
static public ClassType throwable_type = ClassType.make("java.lang.Throwable");
static public Type[] typeArray0 = new Type[0];
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/