You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2018/01/05 20:05:11 UTC
[geode] branch develop updated: GEODE-4158: Correct the detection
of Geode-internal classes for serialization. - Remove consideration of any
class under org.apache as a Geode-internal class that resulted from a
search-and-replace.
This is an automated email from the ASF dual-hosted git repository.
upthewaterspout pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new 193bb07 GEODE-4158: Correct the detection of Geode-internal classes for serialization. - Remove consideration of any class under org.apache as a Geode-internal class that resulted from a search-and-replace.
193bb07 is described below
commit 193bb0754dcd20db9c1c8a8f52d0a57d70260c39
Author: Sarge <md...@pivotal.io>
AuthorDate: Fri Dec 22 12:29:06 2017 -0800
GEODE-4158: Correct the detection of Geode-internal classes for serialization.
- Remove consideration of any class under org.apache as a Geode-internal
class that resulted from a search-and-replace.
Signed-off-by: Dan Smith <ds...@pivotal.io>
---
.../geode/internal/InternalDataSerializer.java | 7 ++-
.../pdx/internal/AutoSerializableManager.java | 26 ++++++---
.../internal/InternalDataSerializerJUnitTest.java | 63 ++++++++++++++++++++++
.../geode/pdx/AutoSerializableJUnitTest.java | 38 +++++++++++++
4 files changed, 124 insertions(+), 10 deletions(-)
diff --git a/geode-core/src/main/java/org/apache/geode/internal/InternalDataSerializer.java b/geode-core/src/main/java/org/apache/geode/internal/InternalDataSerializer.java
index c3b890b..313cd27 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/InternalDataSerializer.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/InternalDataSerializer.java
@@ -1702,13 +1702,12 @@ public abstract class InternalDataSerializer extends DataSerializer implements D
}
/**
- * Test to see if the object is in the gemfire package, to see if we should pass it on to a users
+ * Test to see if the object is in the gemfire package, to see if we should pass it on to a user's
* custom serializater.
*/
- private static boolean isGemfireObject(Object o) {
+ static boolean isGemfireObject(Object o) {
return (o instanceof Function // fixes 43691
- || o.getClass().getName().startsWith("org.apache.")
- || o.getClass().getName().startsWith("org.apache.geode"))
+ || o.getClass().getName().startsWith("org.apache.geode."))
&& !(o instanceof PdxSerializerObject);
}
diff --git a/geode-core/src/main/java/org/apache/geode/pdx/internal/AutoSerializableManager.java b/geode-core/src/main/java/org/apache/geode/pdx/internal/AutoSerializableManager.java
index c3297ae..ddac809 100644
--- a/geode-core/src/main/java/org/apache/geode/pdx/internal/AutoSerializableManager.java
+++ b/geode-core/src/main/java/org/apache/geode/pdx/internal/AutoSerializableManager.java
@@ -199,18 +199,32 @@ public class AutoSerializableManager {
return result;
}
- public boolean defaultIsClassAutoSerialized(Class<?> clazz) {
- if (clazz.isEnum()) {
- return false;
- }
- String className = clazz.getName();
+ /**
+ * Determines whether objects of the named class are excluded from auto-serialization. The classes
+ * that are excluded are Geode-internal classes and Java classes.
+ *
+ * @param className Class name including packages.
+ * @return <code>true</code> if the named class is excluded.
+ */
+ public boolean isExcluded(String className) {
if (!noHardcodedExcludes) {
for (Pattern p : hardcodedExclusions) {
if (p.matcher(className).matches()) {
- return false;
+ return true;
}
}
}
+ return false;
+ }
+
+ public boolean defaultIsClassAutoSerialized(Class<?> clazz) {
+ if (clazz.isEnum()) {
+ return false;
+ }
+ String className = clazz.getName();
+ if (isExcluded(className)) {
+ return false;
+ }
for (Pattern p : classPatterns) {
if (p.matcher(className).matches()) {
diff --git a/geode-core/src/test/java/org/apache/geode/internal/InternalDataSerializerJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/InternalDataSerializerJUnitTest.java
new file mode 100755
index 0000000..2e5a724
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/InternalDataSerializerJUnitTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.geode.internal;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Properties;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.simple.SimpleLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.InternalGemFireException;
+import org.apache.geode.cache.execute.Function;
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.examples.security.ExampleSecurityManager;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+/**
+ * Tests the functionality of the {@link InternalDataSerializer} class.
+ */
+@Category(UnitTest.class)
+public class InternalDataSerializerJUnitTest {
+ @Test
+ public void testIsGemfireObject() {
+ assertTrue("Instances of Function are GemFire objects",
+ InternalDataSerializer.isGemfireObject(new TestFunction()));
+ assertFalse("Instances of PdxSerializaerObject are NOT GemFire objects",
+ InternalDataSerializer.isGemfireObject(new TestPdxSerializerObject()));
+ assertFalse("Instances of anything under org.apache. are GemFire objects",
+ InternalDataSerializer.isGemfireObject(new SimpleLogger("", Level.OFF, false, false, false,
+ false, "", null, new PropertiesUtil(new Properties()), null)));
+ assertTrue("Instances of anything in org.apache.geode. are GemFire objects",
+ InternalDataSerializer.isGemfireObject(new InternalGemFireException()));
+ assertTrue("Instances of anything under org.apache.geode. are GemFire objects",
+ InternalDataSerializer.isGemfireObject(new ExampleSecurityManager()));
+ }
+
+ class TestFunction implements Function {
+ @Override
+ public void execute(FunctionContext context) {
+ // NOP
+ }
+ }
+
+ class TestPdxSerializerObject implements PdxSerializerObject {
+ }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/pdx/AutoSerializableJUnitTest.java b/geode-core/src/test/java/org/apache/geode/pdx/AutoSerializableJUnitTest.java
index 41c1b33..4514a9c 100644
--- a/geode-core/src/test/java/org/apache/geode/pdx/AutoSerializableJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/pdx/AutoSerializableJUnitTest.java
@@ -1234,6 +1234,44 @@ public class AutoSerializableJUnitTest {
}
/*
+ * Tests the exclusion algorithm to verify that it can be disabled.
+ */
+ @Test
+ public void testNoHardCodedExcludes() {
+ System.setProperty(
+ DistributionConfig.GEMFIRE_PREFIX + "auto.serialization.no.hardcoded.excludes", "true");
+ setupSerializer();
+ assertFalse(manager.isExcluded("com.gemstone.gemfire.GemFireException"));
+ assertFalse(manager.isExcluded("com.gemstoneplussuffix.gemfire.GemFireException"));
+ assertFalse(manager.isExcluded("org.apache.geode.GemFireException"));
+ assertFalse(manager.isExcluded("org.apache.geodeplussuffix.gemfire.GemFireException"));
+ assertFalse(manager.isExcluded("javax.management.MBeanException"));
+ assertFalse(manager.isExcluded("javaxplussuffix.management.MBeanException"));
+ assertFalse(manager.isExcluded("java.lang.Exception"));
+ assertFalse(manager.isExcluded("javaplussuffix.lang.Exception"));
+ assertFalse(manager.isExcluded("com.example.Moof"));
+ }
+
+ /*
+ * Tests the exclusion algorithm to verify that it does not cast too wide of a net.
+ */
+ @Test
+ public void testHardCodedExcludes() {
+ System.setProperty(
+ DistributionConfig.GEMFIRE_PREFIX + "auto.serialization.no.hardcoded.excludes", "false");
+ setupSerializer();
+ assertTrue(manager.isExcluded("com.gemstone.gemfire.GemFireException"));
+ assertFalse(manager.isExcluded("com.gemstoneplussuffix.gemfire.GemFireException"));
+ assertTrue(manager.isExcluded("org.apache.geode.GemFireException"));
+ assertFalse(manager.isExcluded("org.apache.geodeplussuffix.gemfire.GemFireException"));
+ assertTrue(manager.isExcluded("javax.management.MBeanException"));
+ assertFalse(manager.isExcluded("javaxplussuffix.management.MBeanException"));
+ assertTrue(manager.isExcluded("java.lang.Exception"));
+ assertFalse(manager.isExcluded("javaplussuffix.lang.Exception"));
+ assertFalse(manager.isExcluded("com.example.Moof"));
+ }
+
+ /*
* This test intends to simulate what happens when differing class loaders hold references to the
* same named class - something that would happen in the context of an app server. We need to
* ensure that the AutoSerializableManager tracks these as separate classes even though they might
--
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].