-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix JDK17+ assistedinject private lookup behavior by catching Inacces…
…sibleObjectException (as Throwable) when attempting to reflect on private JDK internals. Rewrite the way we iterate through method handle lookups. Don't cache fallback behavior. Instead, eagerly discover what the JDK supports & cache that. On use, if it fails (likely because a proper lookups wasn't supplied), then fallback (but do not cache the fallback). All these shenanigans are only necessary if javac generated a default method that Guice needs to invoke. Because AssistedInject uses a JDK Proxy, which also proxies default interface methods, we need to use invokespecial to target the proxy (otherwise proxying the method will end up with a stack overflow due to infinite recursion). Note that if we implemented this by code generation, we wouldn't need these hacks... so we take some pains to allow non-public factories without *requiring* the user to call withLookups(..). But the workarounds don't always work, so we still need the withLookups(..) method. PiperOrigin-RevId: 423822309
- Loading branch information
Showing
3 changed files
with
216 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
extensions/assistedinject/src/com/google/inject/assistedinject/internal/LookupTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.google.inject.assistedinject.internal; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
|
||
/** | ||
* An interface in a different package, so that AssistedInject's main package can't see it. Used at | ||
* runtime to determine which kind of Lookup method we'll support. | ||
*/ | ||
class LookupTester { | ||
static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); | ||
|
||
interface Hidden { | ||
default Hidden method() { | ||
return null; | ||
} | ||
} | ||
|
||
private LookupTester() {} | ||
} |
Oops, something went wrong.