[jboss-svn-commits] JBL Code SVN: r29293 - in labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule: expression and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Sep 10 09:06:33 EDT 2009
Author: adinn
Date: 2009-09-10 09:06:33 -0400 (Thu, 10 Sep 2009)
New Revision: 29293
Modified:
labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/RuleElement.java
labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/expression/StringPlusExpression.java
Log:
String plus now substitutes null for null operands -- fixes BYTEMAN-31
Modified: labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/RuleElement.java
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/RuleElement.java 2009-09-10 12:39:35 UTC (rev 29292)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/RuleElement.java 2009-09-10 13:06:33 UTC (rev 29293)
@@ -33,6 +33,7 @@
import org.jboss.byteman.rule.helper.HelperAdapter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Label;
import java.io.StringWriter;
@@ -204,8 +205,20 @@
{
assert toType == Type.STRING;
if (fromType.isObject() || fromType.isArray()) {
- // use the toString method
+ // use the toString method if the object is non null otherwise just replace it with null
+ Label elseLabel = new Label();
+ Label endLabel = new Label();
+ // if (object == null)
+ mv.visitInsn(Opcodes.DUP);
+ mv.visitJumpInsn(Opcodes.IFNONNULL, elseLabel);
+ // then string = "null"
+ mv.visitInsn(Opcodes.POP);
+ mv.visitLdcInsn("null");
+ mv.visitJumpInsn(Opcodes.GOTO, endLabel);
+ // else string = object.toString()
+ mv.visitLabel(elseLabel);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;");
+ mv.visitLabel(endLabel);
} else if (fromType == Type.Z) {
// use the toString method
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "toString", "(Z)Ljava/lang/String;");
Modified: labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/expression/StringPlusExpression.java
===================================================================
--- labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/expression/StringPlusExpression.java 2009-09-10 12:39:35 UTC (rev 29292)
+++ labs/jbosstm/workspace/adinn/byteman/trunk/src/org/jboss/byteman/rule/expression/StringPlusExpression.java 2009-09-10 13:06:33 UTC (rev 29293)
@@ -33,6 +33,7 @@
import org.jboss.byteman.rule.grammar.ParseNode;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Label;
/**
* A binary string concatenation operator expression
@@ -60,7 +61,7 @@
Object value1 = getOperand(0).interpret(helper);
Object value2 = getOperand(1).interpret(helper);
String string1 = value1.toString();
- String string2 = value2.toString();
+ String string2 = (value2 == null ? "null" : value2.toString());
return string1 + string2;
}
@@ -72,7 +73,9 @@
int currentStack = currentStackHeights.stackCount;
int expected = 2;
- // compile and type convert each operand
+ // compile and type convert each operand n.b. the type conversion will ensure that
+ // null operands are replaced with "null"
+
oper0.compile(mv, currentStackHeights, maxStackHeights);
compileTypeConversion(oper0.getType(), type, mv, currentStackHeights, maxStackHeights);
oper1.compile(mv, currentStackHeights, maxStackHeights);
@@ -82,6 +85,7 @@
// by employing a StringBuffer but for now we will just evaluate the left and right operand and
// then call concat to join them
// add two strings leaving one string
+
expected = 1;
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "concat", "(Ljava/lang/String;)Ljava/lang/String;");
More information about the jboss-svn-commits
mailing list