From 87e45d5d7271d332a9456f3a50619d9fdde044d4 Mon Sep 17 00:00:00 2001 From: Branhub Date: Thu, 16 Apr 2026 23:31:35 +0800 Subject: [PATCH] ignore synthetic method when try to find ThriftEnumValue method --- .../codec/metadata/ThriftEnumMetadata.java | 3 ++ .../drift/codec/GenericReturnValue.java | 22 +++++++++++ .../drift/codec/GenericReturnValueEnum.java | 38 +++++++++++++++++++ .../drift/codec/TestThriftCodecManager.java | 8 ++++ 4 files changed, 71 insertions(+) create mode 100644 drift-codec/src/test/java/io/airlift/drift/codec/GenericReturnValue.java create mode 100644 drift-codec/src/test/java/io/airlift/drift/codec/GenericReturnValueEnum.java diff --git a/drift-codec/src/main/java/io/airlift/drift/codec/metadata/ThriftEnumMetadata.java b/drift-codec/src/main/java/io/airlift/drift/codec/metadata/ThriftEnumMetadata.java index 89b1deccb..3526322a7 100644 --- a/drift-codec/src/main/java/io/airlift/drift/codec/metadata/ThriftEnumMetadata.java +++ b/drift-codec/src/main/java/io/airlift/drift/codec/metadata/ThriftEnumMetadata.java @@ -55,6 +55,9 @@ public ThriftEnumMetadata( Method enumValueMethod = null; for (Method method : enumClass.getMethods()) { + if (method.isSynthetic()) { + continue; + } if (method.isAnnotationPresent(ThriftEnumValue.class)) { checkArgument( Modifier.isPublic(method.getModifiers()), diff --git a/drift-codec/src/test/java/io/airlift/drift/codec/GenericReturnValue.java b/drift-codec/src/test/java/io/airlift/drift/codec/GenericReturnValue.java new file mode 100644 index 000000000..81fbcb2a3 --- /dev/null +++ b/drift-codec/src/test/java/io/airlift/drift/codec/GenericReturnValue.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2012 Facebook, Inc. + * + * Licensed 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 io.airlift.drift.codec; + +public interface GenericReturnValue +{ + @SuppressWarnings("unused") // used to test bridge method + T getEnumValue(); +} diff --git a/drift-codec/src/test/java/io/airlift/drift/codec/GenericReturnValueEnum.java b/drift-codec/src/test/java/io/airlift/drift/codec/GenericReturnValueEnum.java new file mode 100644 index 000000000..05ce73489 --- /dev/null +++ b/drift-codec/src/test/java/io/airlift/drift/codec/GenericReturnValueEnum.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2012 Facebook, Inc. + * + * Licensed 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 io.airlift.drift.codec; + +import io.airlift.drift.annotations.ThriftEnum; +import io.airlift.drift.annotations.ThriftEnumValue; + +@ThriftEnum +public enum GenericReturnValueEnum implements GenericReturnValue { + GENERIC_RETURN_VALUE_ENUMValueEnum(1); + + private final Integer enumValue; + + GenericReturnValueEnum(Integer enumValue) + { + this.enumValue = enumValue; + } + + @ThriftEnumValue + @Override + public Integer getEnumValue() + { + return enumValue; + } +} diff --git a/drift-codec/src/test/java/io/airlift/drift/codec/TestThriftCodecManager.java b/drift-codec/src/test/java/io/airlift/drift/codec/TestThriftCodecManager.java index a212383ba..f76b6d1b2 100644 --- a/drift-codec/src/test/java/io/airlift/drift/codec/TestThriftCodecManager.java +++ b/drift-codec/src/test/java/io/airlift/drift/codec/TestThriftCodecManager.java @@ -194,6 +194,14 @@ public void testAddUnionCodec() testRoundTripSerialize(union); } + @Test + private void testGenericReturnValueEnum() throws Exception + { + ThriftEnumMetadata enumMetadata = thriftEnumMetadata(GenericReturnValueEnum.class); + testRoundTripSerialize(enumType(enumMetadata), GenericReturnValueEnum.GENERIC_RETURN_VALUE_ENUMValueEnum); + testRoundTripSerialize(list(enumType(enumMetadata)), ImmutableList.copyOf(GenericReturnValueEnum.values())); + } + private void testRoundTripSerialize(T value) throws Exception {