Update version and enhance hidden class instantiation#273
Update version and enhance hidden class instantiation#273twisti-dev merged 2 commits intoversion/1.21.11from
Conversation
There was a problem hiding this comment.
Pull request overview
This PR bumps the project version and updates hidden-class invoker instantiation to use a MethodHandle constructor invocation, aiming to improve reliability and diagnostics when creating hidden invoker instances.
Changes:
- Switch hidden class instantiation from reflection (
getDeclaredConstructor().newInstance()) toLookup.findConstructor(...).invoke(). - Add error wrapping during hidden class instantiation by converting thrown failures into
ReflectiveOperationException. - Bump version from
1.21.11-2.73.0to1.21.11-2.73.1.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
surf-api-core/surf-api-core-api/src/main/java/dev/slne/surf/surfapi/core/api/invoker/HiddenInvokerUtil.java |
Updates hidden-class instantiation approach and adjusts related JavaDoc. |
gradle.properties |
Increments project version for the bug fix release. |
|
|
||
| try { | ||
| return invokerInterface.cast(constructor.invoke()); | ||
| } catch (Throwable e) { |
There was a problem hiding this comment.
The new catch (Throwable e) wraps all Errors (e.g., OutOfMemoryError, StackOverflowError) into a ReflectiveOperationException, which can mask fatal JVM conditions and change failure semantics. Consider rethrowing Error (or at least VirtualMachineError/ThreadDeath/LinkageError) and only wrapping non-fatal throwables from MethodHandle.invoke() into ReflectiveOperationException.
| } catch (Throwable e) { | |
| } catch (Throwable e) { | |
| if (e instanceof Error) { | |
| throw (Error) e; | |
| } |
| * @param methodType the expected {@link MethodType} for non-suspend handler methods. | ||
| * @return an {@link InvokerClassData} instance containing the resolved handler method | ||
| * information, along with metadata on whether it's a suspend function. | ||
| * information, along with metadata on whether it's a suspend function. |
There was a problem hiding this comment.
JavaDoc formatting regression: the continuation line after @return lost indentation/alignment (* information, ...). This reads like a paragraph break and is inconsistent with the surrounding JavaDoc style; re-indent to keep the wrapped @return description aligned.
| * information, along with metadata on whether it's a suspend function. | |
| * information, along with metadata on whether it's a suspend function. |
This pull request includes a version bump and a bug fix for hidden class instantiation in the core API. The most significant change addresses how hidden classes are instantiated, improving reliability and error handling.
Core API improvements
HiddenInvokerUtil.javato use aMethodHandlefor calling the constructor of hidden classes, and added improved error handling by catchingThrowableand rethrowing as aReflectiveOperationExceptionfor better diagnostics.Versioning
gradle.propertiesfrom1.21.11-2.73.0to1.21.11-2.73.1to reflect the bug fix.