[
https://issues.apache.org/jira/browse/IGNITE-8547?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16482835#comment-16482835
]
Ilya Kasnacheev commented on IGNITE-8547:
-----------------------------------------
There's at least two approaches. Both involve fixing
OptimizedObjectOutputStream.write0.
Approach 1:
{code}
if (obj instanceof Throwable && !(obj instanceof Externalizable) ||
BinaryUtils.isEnum(obj.getClass())) {
writeByte(JDK);
// Just let the JDK serialize our enum.
{code}
Approach 2:
{code}
Class cls;
if (obj instanceof Object[])
cls = Object[].class;
else if (BinaryUtils.isEnum(obj.getClass()))
cls = ((Enum)obj).getDeclaringClass();
else
cls = obj.getClass();
OptimizedClassDescriptor desc = classDescriptor(clsMap, cls,
ctx, mapper);
{code}
Use declaring class for enum, hope that it gets interpreted correctly on the
other side (looks like it does)
[~vkulichenko] I would love to hear your input on this one.
> Deserialization of Enum values as anonymous classes may cause deadlock
> ----------------------------------------------------------------------
>
> Key: IGNITE-8547
> URL: https://issues.apache.org/jira/browse/IGNITE-8547
> Project: Ignite
> Issue Type: Bug
> Affects Versions: 1.9
> Reporter: Ilya Kasnacheev
> Assignee: Ilya Kasnacheev
> Priority: Major
> Attachments: MarshallerDeadlockMultiJvmTest.java
>
>
> Due to the following problem:
> {code}
> package jvmtest;
> import java.util.ArrayList;
> import java.util.List;
> import java.util.concurrent.BrokenBarrierException;
> import java.util.concurrent.CyclicBarrier;
> public class LegTypeTest {
> public static void main(String[] args) throws InterruptedException,
> BrokenBarrierException {
> List<Thread> threadList = new ArrayList<>();
> CyclicBarrier b1 = new CyclicBarrier(16);
> CyclicBarrier b2 = new CyclicBarrier(17);
> for (int i = 0; i < 16; i++) {
> final int ii = i;
> Thread thread = new Thread(() -> {
> try {
> b1.await();
> if (ii % 2 == 0)
> Class.forName("jvmtest.LegTypeTest$E$1");
> if (ii % 2 == 1)
> Class.forName("jvmtest.LegTypeTest$E");
> b2.await();
> } catch (Exception e) {
> e.printStackTrace();
> }
> });
> thread.start();
> threadList.add(thread);
> }
> b2.await();
> for (Thread thread : threadList) {
> thread.join();
> }
> }
> private enum E {
> A("A"),
> B("B") {
> @Override
> public String virtual() {
> return null;
> }
> };
> private String displayString;
> E(String displayString) {
> this.displayString = displayString;
> }
> public String virtual() {
> return displayString;
> }
> }
> }
> {code}
> When doing Class.forName on different enum values deadlock can be caused. And
> that's exactly what OptimizedMarshaller does.
> See also the attached test.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)