Author: cbegin
Date: Wed Jan 20 03:33:22 2010
New Revision: 901043

URL: http://svn.apache.org/viewvc?rev=901043&view=rev
Log:
fixed NPE on null primitives

Modified:
    
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperProxy.java

Modified: 
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperProxy.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperProxy.java?rev=901043&r1=901042&r2=901043&view=diff
==============================================================================
--- 
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperProxy.java
 (original)
+++ 
ibatis/java/ibatis-3/trunk/ibatis-3-core/src/main/java/org/apache/ibatis/binding/MapperProxy.java
 Wed Jan 20 03:33:22 2010
@@ -5,17 +5,42 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
+import java.sql.SQLException;
+import java.util.HashSet;
+import java.util.Set;
 
 public class MapperProxy implements InvocationHandler {
 
+  private static final Set<String> OBJECT_METHODS = new HashSet<String>() {{
+    add("toString");
+    add("getClass");
+    add("hashCode");
+    add("equals");
+    add("wait");
+    add("notify");
+    add("notifyAll");
+  }};
+
   private SqlSession sqlSession;
 
   private <T> MapperProxy(SqlSession sqlSession) {
     this.sqlSession = sqlSession;
   }
-
+  
   public Object invoke(Object proxy, Method method, Object[] args) throws 
Throwable {
-    return new MapperMethod(method, sqlSession).execute(args);
+    try {
+      if (!OBJECT_METHODS.contains(method.getName())) {
+        final MapperMethod mapperMethod = new MapperMethod(method, sqlSession);
+        final Object result = mapperMethod.execute(args);
+        if (result == null && method.getReturnType().isPrimitive()) {
+          throw new BindingException("Mapper method '"+ method.getName()+"' 
("+method.getDeclaringClass()+") attempted to return null from a method with a 
primitive return type ("+method.getReturnType()+").");
+        }
+        return result;
+      }
+    } catch (SQLException e) {
+      e.printStackTrace();
+    }
+    return null;
   }
 
   public static <T> T newMapperProxy(Class<T> mapperInterface, SqlSession 
sqlSession) {


Reply via email to