Skip to content

Commit 7b25785

Browse files
committed
Bug 24558376 - Fix Serializer.getName to not throw java.lang.NoClassDefFoundError: javax or jakarta inject.Named when optional inject jar is missing
(auto-submit 115805 after successfully running remote remote.full) Job ID: job.9.20250423200751.8766 (auto-submit integ 115832 main -> coherence-ce/main after successfully running remote remote.full) Job ID: job.9.20250423223501.5806 [git-p4: depot-paths = "//dev/coherence-ce/main/": change = 115834]
1 parent fbabcb2 commit 7b25785

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

prj/coherence-core/src/main/java/com/tangosol/io/Serializer.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
55
* https://oss.oracle.com/licenses/upl.
@@ -20,6 +20,8 @@
2020
import java.util.Map;
2121
import java.util.ServiceLoader;
2222

23+
import java.util.concurrent.atomic.AtomicBoolean;
24+
2325
/**
2426
* The Serializer interface provides the capability of reading and writing a
2527
* Java object from and to an in-memory buffer.
@@ -115,7 +117,19 @@ default <T> T deserialize(ReadBuffer.BufferInput in, Class<? extends T> clazz)
115117
*/
116118
default String getName()
117119
{
118-
Named named = getClass().getAnnotation(Named.class);
120+
Named named = null;
121+
122+
if (CLZ_INJECT_NAMED_FOUND.get())
123+
{
124+
try
125+
{
126+
named = getClass().getAnnotation(Named.class);
127+
}
128+
catch (NoClassDefFoundError e)
129+
{
130+
CLZ_INJECT_NAMED_FOUND.compareAndSet(true, false);
131+
}
132+
}
119133
return named == null ? null : named.value();
120134
}
121135

@@ -208,4 +222,6 @@ private static <T> Map<String, SerializerFactory> loadSerializers(ServiceLoader<
208222
}
209223
return mapSerializer;
210224
}
225+
226+
static AtomicBoolean CLZ_INJECT_NAMED_FOUND = new AtomicBoolean(true);
211227
}

prj/test/unit/coherence-tests/src/test/java/com/tangosol/io/pof/SerializerTest.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
/*
2-
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77
package com.tangosol.io.pof;
88

99

1010
import org.junit.Before;
1111
import org.junit.Test;
1212

13+
import com.tangosol.util.NullImplementation;
14+
1315
import java.io.IOException;
1416

17+
import static org.junit.Assert.fail;
18+
1519

1620
/**
1721
* Unit tests of custom serializer/deserialiser.
@@ -50,6 +54,22 @@ public void testSerialization ()
5054
azzert(cResult.getProduct().getBalance() == cResult.getBalance());
5155
}
5256

57+
@Test
58+
public void testDefaultGetName()
59+
{
60+
try
61+
{
62+
// assert this no longer throws NoClassDefFoundError for optional Named.class not being found.
63+
// This class implementation does not implement getName() and relies on default Serializer.getName().
64+
NullImplementation.getPofContext().getName();
65+
}
66+
catch (NoClassDefFoundError e)
67+
{
68+
e.printStackTrace();
69+
fail("Serializer.getName() must not throw NoClassDefFoundError for optional Named.class not being found.");
70+
}
71+
}
72+
5373
public static class Balance
5474
{
5575
private double m_dflBalance;

0 commit comments

Comments
 (0)