Search code examples
spring-bootjava-8enumsruntime-errorignite

Conflicting enum values java


I have 2 enums defined as below in 2 separate files: MyErrorCodes.java

@Getter
public enum MyErrorCodes implements ErrorCode {
    ERROR1(90, 1, 01),
    ERROR2(90, 1, 02),
    ERROR3(90, 1, 03),
    ERROR4(90, 1, 04),
    ERROR5(90, 1, 05);
    ....
}

ErrorCategory.java

public class ErrorCategory {
@AllArgsConstructor
    public enum ErrorCodes {
        EXECUTION_ERROR("execution.error", "Error in executing {0}.", INTERNAL_ERROR,
                             MyErrorCodes.ERROR1),
        DESERIALIZATION_ERROR("...", "...",BAD_REQUEST_ERROR, MyErrorCodes.ERROR2),
        DEFAULT_INTERNAL_ERROR("...", "...", INTERNAL_ERROR, MyErrorCodes.ERROR3),
        INVALID_RESPONSE("...", "...", INTERNAL_ERROR, MyErrorCodes.ERROR4),
        MAPPING_ERROR("...", "...", INTERNAL_ERROR, MyErrorCodes.ERROR5);
   }
}

At Runtime I am getting error:

Conflicting enum values. Name 'ERROR4' uses ordinal value (4) that is also used for name 'MAPPING_ERROR' 

ERROR4 is 4th element in enum#1 while MAPPING_ERROR is 5th element in the enum#2. Then Why am I getting conflict error when they are completely different enums?

P.S. the interface implemented by enum#1 looks like this:

public interface ErrorCode {
    int getErrorCode();
    String getKey();

}

stacktrace:

at io.opentracing.contrib.concurrent.TracedRunnable.run(TracedRunnable.java:30)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
   
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.apache.ignite.binary.BinaryObjectException: Conflicting enum values. Name 'ERROR4' uses ordinal value (4) that is also used for name 'MAPPING_ERROR'
    at org.apache.ignite.internal.binary.BinaryUtils.mergeEnumValues(BinaryUtils.java:2538)
    at org.apache.ignite.internal.binary.BinaryUtils.mergeMetadata(BinaryUtils.java:1028)
    at org.apache.ignite.internal.processors.cache.binary.BinaryMetadataTransport.requestMetadataUpdate(BinaryMetadataTransport.java:211)
    at org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.addMeta(CacheObjectBinaryProcessorImpl.java:606)
    at org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$1.addMeta(CacheObjectBinaryProcessorImpl.java:288)
    at org.apache.ignite.internal.binary.BinaryContext.registerUserClassDescriptor(BinaryContext.java:828)
    at org.apache.ignite.internal.binary.BinaryContext.registerDescriptor(BinaryContext.java:784)
    at org.apache.ignite.internal.binary.BinaryContext.registerClass(BinaryContext.java:581)
    at org.apache.ignite.internal.binary.BinaryContext.registerClass(BinaryContext.java:556)
    at org.apache.ignite.internal.binary.BinaryWriterExImpl.doWriteEnum(BinaryWriterExImpl.java:829)
    at org.apache.ignite.internal.binary.BinaryWriterExImpl.writeEnumField(BinaryWriterExImpl.java:1323)
    at org.apache.ignite.internal.binary.BinaryFieldAccessor$DefaultFinalClassAccessor.write0(BinaryFieldAccessor.java:670)
    at org.apache.ignite.internal.binary.BinaryFieldAccessor.write(BinaryFieldAccessor.java:157)
    ... 115 common frames omitted
    ```

Solution

  • Okay so here is what we did and found out regarding the issue:

    We were using ignite cluster for our deployment purpose, we updated the ignite version from 6 to 7 and that solved the issue.

    Ignite caches the enum values, so When we introduce new enum values we should add to the end to increment the ordinal to avoid conflicts in future or clear the cache.