Skip to content

Commit 3b5da5d

Browse files
authored
Update version and enhance hidden class instantiation (#273)
2 parents 1d7247c + a18ed4b commit 3b5da5d

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
77
javaVersion=25
88
mcVersion=1.21.11
99
group=dev.slne.surf
10-
version=1.21.11-2.73.0
10+
version=1.21.11-2.73.1
1111
relocationPrefix=dev.slne.surf.surfapi.libs
1212
snapshot=false

surf-api-core/surf-api-core-api/src/main/java/dev/slne/surf/surfapi/core/api/invoker/HiddenInvokerUtil.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,13 @@ static <I> I createInvoker(
134134
final List<Object> classData = List.of(target, payloadClass, method, privateLookupIn, isSuspend);
135135
final MethodHandles.Lookup hiddenClassLookup = lookup.defineHiddenClassWithClassData(templateBytes, classData, true);
136136

137-
return hiddenClassLookup.lookupClass()
138-
.asSubclass(invokerInterface)
139-
.getDeclaredConstructor()
140-
.newInstance();
137+
final MethodHandle constructor = hiddenClassLookup.findConstructor(hiddenClassLookup.lookupClass(), MethodType.methodType(void.class));
138+
139+
try {
140+
return invokerInterface.cast(constructor.invoke());
141+
} catch (Throwable e) {
142+
throw new ReflectiveOperationException("Failed to instantiate hidden class", e);
143+
}
141144
}
142145

143146
/**
@@ -192,7 +195,7 @@ public static InvokerClassData loadClassData(
192195
* the hidden class.
193196
* @param methodType the expected {@link MethodType} for non-suspend handler methods.
194197
* @return an {@link InvokerClassData} instance containing the resolved handler method
195-
* information, along with metadata on whether it's a suspend function.
198+
* information, along with metadata on whether it's a suspend function.
196199
* @throws ReflectiveOperationException if class data extraction or handle resolution fails.
197200
*/
198201
public static InvokerClassData loadClassDataWithAutoSuspend(

0 commit comments

Comments
 (0)