This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Passing #!null as <java.lang.String>


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]