-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Use synthetic functions of kotlin jvm inline class #4066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0e53942
02f3fd2
1dbce7b
c1d08c2
ff989c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.fasterxml.jackson.databind.ext; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
|
||
public class KotlinSupport { | ||
public static boolean isJvmInlineClassSyntheticConstructor(Constructor<?> ctor) { | ||
Class<?>[] params = ctor.getParameterTypes(); | ||
if (params.length == 0) { | ||
return false; | ||
} | ||
|
||
Class<?> lastParam = params[params.length - 1]; | ||
return ctor.isSynthetic() && lastParam.getName().equals("kotlin.jvm.internal.DefaultConstructorMarker"); | ||
} | ||
|
||
public static boolean isJvmInlineClassSyntheticBoxingFunction(Method method) { | ||
return Modifier.isStatic(method.getModifiers()) | ||
&& method.isSynthetic() | ||
&& method.getName().equals("box-impl"); | ||
} | ||
Comment on lines
+18
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As commented here, using only Therefore, this change should be removed. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
import com.fasterxml.jackson.databind.AnnotationIntrospector; | ||
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.databind.ext.KotlinSupport; | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedClass.Creators; | ||
import com.fasterxml.jackson.databind.type.TypeFactory; | ||
import com.fasterxml.jackson.databind.util.ClassUtil; | ||
|
@@ -282,7 +283,9 @@ private static boolean _isIncludableFactoryMethod(Method m) | |
} | ||
// 09-Nov-2020, ckozak: Avoid considering synthetic methods such as | ||
// lambdas used within methods because they're not relevant. | ||
return !m.isSynthetic(); | ||
return !m.isSynthetic() | ||
// 02-Sep-2023: As per [databind#4066] Kotlin needs some synthetic factory methods | ||
|| KotlinSupport.isJvmInlineClassSyntheticBoxingFunction(m); | ||
} | ||
|
||
protected AnnotatedConstructor constructDefaultConstructor(ClassUtil.Ctor ctor, | ||
|
@@ -406,8 +409,10 @@ private final AnnotationMap collectAnnotations(AnnotatedElement main, AnnotatedE | |
return c.asAnnotationMap(); | ||
} | ||
|
||
// for [databind#1005]: do not use or expose synthetic constructors | ||
private static boolean isIncludableConstructor(Constructor<?> c) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /cc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think current There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agreed 👍🏻 |
||
return !c.isSynthetic(); | ||
// for [databind#1005]: do not use or expose synthetic constructors | ||
return !c.isSynthetic() | ||
// 02-Sep-2023: As per [databind#4066] Kotlin needs some synthetic constructors | ||
|| KotlinSupport.isJvmInlineClassSyntheticConstructor(c); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code also covers constructors that do not actually contain
value class
as an argument.The following is a class definition in
Kotlin
and its constructors taken from the decompiled result.You can see that the
value class
is not used, but the argument of the synthetic constructor ends withDefaultConstructorMarker
.I can't think of any other way to write it myself, but I think it should at least be supplemented with a comment.