You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/07/31 19:34:33 UTC
svn commit: r1508965 - in /cxf/trunk:
api/src/main/java/org/apache/cxf/common/util/ASMHelper.java
rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/WrapperHelperCompiler.java
Author: dkulp
Date: Wed Jul 31 17:34:32 2013
New Revision: 1508965
URL: http://svn.apache.org/r1508965
Log:
[CXF-5147] Don't NPE if using a primitive for a holder. If null, don't call the setter so whatever is the default in the wrapper object would end up being used. (basically, same behavior as when a BARE method is used)
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/WrapperHelperCompiler.java
Modified: cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java?rev=1508965&r1=1508964&r2=1508965&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java Wed Jul 31 17:34:32 2013
@@ -38,6 +38,7 @@ import org.apache.cxf.common.util.Reflec
public class ASMHelper {
protected static final Map<Class<?>, String> PRIMITIVE_MAP = new HashMap<Class<?>, String>();
protected static final Map<Class<?>, String> NONPRIMITIVE_MAP = new HashMap<Class<?>, String>();
+ protected static final Map<Class<?>, Integer> PRIMITIVE_ZERO_MAP = new HashMap<Class<?>, Integer>();
protected static final Map<Class<?>, WeakReference<TypeHelperClassLoader>> LOADER_MAP
= new WeakIdentityHashMap<Class<?>, WeakReference<TypeHelperClassLoader>>();
@@ -135,6 +136,11 @@ public class ASMHelper {
public static int IFNONNULL = 0;
public static int SIPUSH = 0;
public static int INVOKESTATIC = 0;
+ public static int ICONST_0;
+ public static int LCONST_0;
+ public static int FCONST_0;
+ public static int DCONST_0;
+
//CHECKSTYLE:ON
static {
try {
@@ -147,6 +153,15 @@ public class ASMHelper {
} catch (Throwable e) {
//ignore
}
+
+ PRIMITIVE_ZERO_MAP.put(Byte.TYPE, Opcodes.ICONST_0);
+ PRIMITIVE_ZERO_MAP.put(Boolean.TYPE, Opcodes.ICONST_0);
+ PRIMITIVE_ZERO_MAP.put(Long.TYPE, Opcodes.LCONST_0);
+ PRIMITIVE_ZERO_MAP.put(Integer.TYPE, Opcodes.ICONST_0);
+ PRIMITIVE_ZERO_MAP.put(Short.TYPE, Opcodes.ICONST_0);
+ PRIMITIVE_ZERO_MAP.put(Character.TYPE, Opcodes.ICONST_0);
+ PRIMITIVE_ZERO_MAP.put(Float.TYPE, Opcodes.FCONST_0);
+ PRIMITIVE_ZERO_MAP.put(Double.TYPE, Opcodes.DCONST_0);
}
}
Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/WrapperHelperCompiler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/WrapperHelperCompiler.java?rev=1508965&r1=1508964&r2=1508965&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/WrapperHelperCompiler.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/WrapperHelperCompiler.java Wed Jul 31 17:34:32 2013
@@ -38,7 +38,6 @@ final class WrapperHelperCompiler extend
final Object objectFactory;
final ClassWriter cw;
-
private WrapperHelperCompiler(Class<?> wrapperType,
Method setMethods[],
Method getMethods[],
@@ -260,22 +259,39 @@ final class WrapperHelperCompiler extend
if (tp.isPrimitive()) {
mv.visitTypeInsn(Opcodes.CHECKCAST, NONPRIMITIVE_MAP.get(tp));
+ Label l45 = createLabel();
+ Label l46 = createLabel();
+ mv.visitInsn(Opcodes.DUP);
+ mv.visitJumpInsn(Opcodes.IFNULL, l45);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, NONPRIMITIVE_MAP.get(tp),
tp.getName() + "Value", "()" + PRIMITIVE_MAP.get(tp));
+ mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
+ periodToSlashes(wrapperType.getName()),
+ setMethods[x].getName(), "(" + getClassCode(tp) + ")V");
+ mv.visitJumpInsn(Opcodes.GOTO, l46);
+ mv.visitLabel(l45);
+ mv.visitInsn(Opcodes.POP);
+ mv.visitLabel(l46);
} else if (JAXBElement.class.isAssignableFrom(tp)) {
mv.visitTypeInsn(Opcodes.CHECKCAST,
periodToSlashes(jaxbMethods[x].getParameterTypes()[0].getName()));
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(objectFactoryClass.getName()),
jaxbMethods[x].getName(),
getMethodSignature(jaxbMethods[x]));
+ mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
+ periodToSlashes(wrapperType.getName()),
+ setMethods[x].getName(), "(" + getClassCode(tp) + ")V");
} else if (tp.isArray()) {
mv.visitTypeInsn(Opcodes.CHECKCAST, getClassCode(tp));
+ mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
+ periodToSlashes(wrapperType.getName()),
+ setMethods[x].getName(), "(" + getClassCode(tp) + ")V");
} else {
mv.visitTypeInsn(Opcodes.CHECKCAST, periodToSlashes(tp.getName()));
+ mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
+ periodToSlashes(wrapperType.getName()),
+ setMethods[x].getName(), "(" + getClassCode(tp) + ")V");
}
- mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
- periodToSlashes(wrapperType.getName()),
- setMethods[x].getName(), "(" + getClassCode(tp) + ")V");
}
}