You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2018/02/16 09:13:49 UTC

aries-rsa git commit: Try to fix stack overflow with DTOs by explicitly checking for DTO

Repository: aries-rsa
Updated Branches:
  refs/heads/master 8cfde96f9 -> 9a816dcc4


Try to fix stack overflow with DTOs by explicitly checking for DTO


Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/9a816dcc
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/9a816dcc
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/9a816dcc

Branch: refs/heads/master
Commit: 9a816dcc4ae632fe6477e15122fd3f89ca1d3c49
Parents: 8cfde96
Author: Christian Schneider <cs...@adobe.com>
Authored: Fri Feb 16 10:13:42 2018 +0100
Committer: Christian Schneider <cs...@adobe.com>
Committed: Fri Feb 16 10:13:42 2018 +0100

----------------------------------------------------------------------
 .../tcp/ser/BasicObjectOutputStream.java        |  4 +-
 .../aries/rsa/provider/tcp/ser/DTOUtil.java     | 71 ++++++++++++++++++++
 .../provider/tcp/TcpProviderPrimitiveTest.java  |  3 -
 3 files changed, 74 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/9a816dcc/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/ser/BasicObjectOutputStream.java
----------------------------------------------------------------------
diff --git a/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/ser/BasicObjectOutputStream.java b/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/ser/BasicObjectOutputStream.java
index 67f1e62..63bc73c 100644
--- a/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/ser/BasicObjectOutputStream.java
+++ b/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/ser/BasicObjectOutputStream.java
@@ -27,8 +27,10 @@ public class BasicObjectOutputStream extends ObjectOutputStream {
             return obj;
         } else if (obj instanceof Version) {
             return new VersionMarker((Version) obj);
-        } else {
+        } else if (DTOUtil.isDTOType(obj.getClass())){
             return new DTOMarker(obj);
+        } else {
+            return obj;
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/9a816dcc/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/ser/DTOUtil.java
----------------------------------------------------------------------
diff --git a/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/ser/DTOUtil.java b/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/ser/DTOUtil.java
new file mode 100644
index 0000000..156b730
--- /dev/null
+++ b/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/ser/DTOUtil.java
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.rsa.provider.tcp.ser;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+/**
+ * Copied from felix converter as the class there is not public
+ */
+class DTOUtil {
+    private DTOUtil() {
+        // Do not instantiate. This is a utility class.
+    }
+
+    static boolean isDTOType(Class<?> cls) {
+        try {
+            cls.getDeclaredConstructor();
+        } catch (NoSuchMethodException | SecurityException e) {
+            // No zero-arg constructor, not a DTO
+            return false;
+        }
+
+        if (cls.getDeclaredMethods().length > 0) {
+            // should not have any methods
+            return false;
+        }
+
+        for (Method m : cls.getMethods()) {
+            try {
+                Object.class.getMethod(m.getName(), m.getParameterTypes());
+            } catch (NoSuchMethodException snme) {
+                // Not a method defined by Object.class (or override of such
+                // method)
+                return false;
+            }
+        }
+
+        boolean foundField = false;
+        for (Field f : cls.getFields()) {
+            int modifiers = f.getModifiers();
+            if (Modifier.isStatic(modifiers)) {
+                // ignore static fields
+                continue;
+            }
+
+            if (!Modifier.isPublic(modifiers)) {
+                return false;
+            }
+            foundField = true;
+        }
+        return foundField;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/9a816dcc/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderPrimitiveTest.java
----------------------------------------------------------------------
diff --git a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderPrimitiveTest.java b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderPrimitiveTest.java
index e2797d9..ea26c54 100644
--- a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderPrimitiveTest.java
+++ b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderPrimitiveTest.java
@@ -43,7 +43,6 @@ import org.easymock.EasyMock;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Version;
@@ -140,7 +139,6 @@ public class TcpProviderPrimitiveTest {
         assertThat(myServiceProxy.callVersionMap(map).entrySet(), everyItem(isIn(map.entrySet())));
     }
 
-    @Ignore
     @Test
     public void testDTO() {
         DTOType dto = new DTOType();
@@ -148,7 +146,6 @@ public class TcpProviderPrimitiveTest {
         assertThat(myServiceProxy.callDTO(dto), samePropertyValuesAs(dto));
     }
     
-    @Ignore
     @Test
     public void testDTOAr() {
         DTOType dto = new DTOType();