Skip to content

Commit 7a1ee4c

Browse files
fix(java): descriptors for beans should not include static methods (#2281)
## What does this PR do? Bean interface method descriptor discovery incorrectly includes static methods like `static Builder builder()`
1 parent b019b25 commit 7a1ee4c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

java/fory-core/src/main/java/org/apache/fory/type/Descriptor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ public static SortedMap<Member, Descriptor> getAllDescriptorsMap(
462462
}
463463
if (clazz.isInterface()) {
464464
for (Method method : clazz.getMethods()) {
465-
if (method.getParameterCount() == 0 && method.getReturnType() != void.class) {
465+
if (method.getParameterCount() == 0
466+
&& method.getReturnType() != void.class
467+
&& !Modifier.isStatic(method.getModifiers())) {
466468
descriptorMap.put(method, new Descriptor(method));
467469
}
468470
}

java/fory-format/src/test/java/org/apache/fory/format/encoder/ImplementInterfaceTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public interface InterfaceType {
3737
NestedType getNested();
3838

3939
PoisonPill getPoison();
40+
41+
static PoisonPill builder() {
42+
return new PoisonPill();
43+
}
4044
}
4145

4246
public interface NestedType {

0 commit comments

Comments
 (0)