This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-fury.git
The following commit(s) were added to refs/heads/main by this push:
new b6f90241 fix(java): compatible low version guava(#1593) (#1594)
b6f90241 is described below
commit b6f90241450d66f273a48c53f564abd0b82d1bf6
Author: 李舒畅 <[email protected]>
AuthorDate: Mon Apr 29 12:15:52 2024 +0800
fix(java): compatible low version guava(#1593) (#1594)
## What does this PR do?
compatible low version guava
## Related issues
- #1593
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/incubator-fury/issues/new/choose)
describing the need to do so and update the document if necessary.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
-->
---
.../serializer/collection/GuavaCollectionSerializers.java | 11 ++++++++++-
.../src/main/java/org/apache/fury/util/unsafe/_JDKAccess.java | 8 +++++++-
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/GuavaCollectionSerializers.java
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/GuavaCollectionSerializers.java
index c7217ec6..b05b378c 100644
---
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/GuavaCollectionSerializers.java
+++
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/GuavaCollectionSerializers.java
@@ -256,11 +256,20 @@ public class GuavaCollectionSerializers {
protected Function computeValue(Class<?> builderClass) {
MethodHandles.Lookup lookup =
_JDKAccess._trustedLookup(builderClass);
MethodHandle ctr = null;
+ boolean lowVersionGuava = false;
try {
ctr =
lookup.findConstructor(builderClass,
MethodType.methodType(void.class, int.class));
} catch (NoSuchMethodException | IllegalAccessException e) {
- Platform.throwException(e);
+ try {
+ ctr = lookup.findConstructor(builderClass,
MethodType.methodType(void.class));
+ lowVersionGuava = true;
+ } catch (NoSuchMethodException | IllegalAccessException e2) {
+ Platform.throwException(e);
+ }
+ }
+ if (lowVersionGuava) {
+ return _JDKAccess.makeJDKFunction(lookup, ctr,
MethodType.methodType(Object.class));
}
return _JDKAccess.makeJDKFunction(lookup, ctr);
}
diff --git
a/java/fury-core/src/main/java/org/apache/fury/util/unsafe/_JDKAccess.java
b/java/fury-core/src/main/java/org/apache/fury/util/unsafe/_JDKAccess.java
index 11e11af1..d10a9df1 100644
--- a/java/fury-core/src/main/java/org/apache/fury/util/unsafe/_JDKAccess.java
+++ b/java/fury-core/src/main/java/org/apache/fury/util/unsafe/_JDKAccess.java
@@ -126,13 +126,19 @@ public class _JDKAccess {
@SuppressWarnings("unchecked")
public static <T, R> Function<T, R> makeJDKFunction(Lookup lookup,
MethodHandle handle) {
+ return makeJDKFunction(lookup, handle, jdkFunctionMethodType);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T, R> Function<T, R> makeJDKFunction(
+ Lookup lookup, MethodHandle handle, MethodType methodType) {
try {
CallSite callSite =
LambdaMetafactory.metafactory(
lookup,
"apply",
MethodType.methodType(Function.class),
- jdkFunctionMethodType,
+ methodType,
handle,
boxedMethodType(handle.type()));
return (Function<T, R>) callSite.getTarget().invokeExact();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]