[kaffe] null string concatenation

Ito Kazumitsu ito.kazumitsu at hitachi-cable.co.jp
Tue Nov 25 03:17:02 PST 2003


Hi,

With reference to the bug:
   http://www.kaffe.org/pipermail/kaffe/2003-November/044458.html

I suggest the following patch:

--- kopi-2.1B/src/kjc/JCompoundAssignmentExpression.java	2002-07-16 03:53:32.000000000 +0900
+++ test/JCompoundAssignmentExpression.java	2003-11-25 19:26:58.000000000 +0900
@@ -239,6 +239,13 @@
 
     if (oper == OPE_PLUS && type.equals(factory.createReferenceType(TypeFactory.RFT_STRING))) {
       //      left.genCode(context, false);
+      /* Isn't it stupid to call String.valueOf(String) ?
+       * But we must do this because it may be null.
+       */
+      code.plantMethodRefInstruction(opc_invokestatic,
+			       "java/lang/String",
+			       "valueOf",
+			       "(Ljava/lang/Object;)Ljava/lang/String;");
       right.genCode(context, false);
       if (!right.getType(factory).isReference()) {
 	code.plantMethodRefInstruction(opc_invokestatic,


By the way, the bytecode which JCompoundAssignmentExpression.java generates
looks quite different from the bytecode produced by gcj or Sun's javac. The
former uses String.concat and the latter uses StringBuffer for string
concatenation.  Which is better?




More information about the kaffe mailing list