[
https://issues.apache.org/jira/browse/GEODE-4158?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16313788#comment-16313788
]
ASF GitHub Bot commented on GEODE-4158:
---------------------------------------
upthewaterspout closed pull request #1219: GEODE-4158: Correct the detection of
Geode-internal classes for seria…
URL: https://github.com/apache/geode/pull/1219
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 5079c07998..205c562862 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
@@ -1701,13 +1701,12 @@ private static void checkPdxCompatible(Object o,
boolean ensurePdxCompatibility)
}
/**
- * 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 c3297aea76..ddac80948a 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 @@ private boolean isRelevant(Class<?> clazz) {
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 0000000000..2e5a72408f
--- /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 41c1b33e29..4514a9cda5 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
@@ -1233,6 +1233,44 @@ public void testGetConfig() throws Exception {
result.getProperty("classes"));
}
+ /*
+ * 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
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Serialization does not correctly identify Geode-internal classes
> ----------------------------------------------------------------
>
> Key: GEODE-4158
> URL: https://issues.apache.org/jira/browse/GEODE-4158
> Project: Geode
> Issue Type: Bug
> Components: serialization
> Reporter: Michael Dodge
> Assignee: Michael Dodge
>
> Reflection-based auto-serialization respects a system property,
> "gemfire.auto.serialization.no.hardcoded.excludes", with regard to excluding
> Geode-internal classes from auto-serialization. However,
> {{InternalDataSerializer}} does not respect that system property and uses
> overly-aggressive prefix matching. For example, {{InternalDataSerializer}}
> should not consider classes under {{org.apache.geode_examples}} to be
> Geode-internal classes as they are from the examples.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)