-
Notifications
You must be signed in to change notification settings - Fork 281
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
[ELY-2514] Update minimum JDK for all modules to 11 #1880
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -17,42 +17,43 @@ | |
*/ | ||
package org.wildfly.security.manager; | ||
|
||
import sun.reflect.Reflection; | ||
import static java.security.AccessController.doPrivileged; | ||
|
||
import java.lang.StackWalker.Option; | ||
import java.security.PrivilegedAction; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* JDK-specific classes which are replaced for different JDK major versions. This class is for JDK 8. | ||
* JDK-specific classes which are replaced for different JDK major versions. This class is for JDK 9. | ||
* @author <a href="mailto:[email protected]">Justin Cook</a> | ||
*/ | ||
final class JDKSpecific { | ||
|
||
private static boolean active; | ||
private static int offset; | ||
|
||
static { | ||
|
||
boolean active = false; | ||
int offset = 0; | ||
try { | ||
// JDK-8014925 - An additional Reflection call may be on the call stack so check the offset needed. | ||
active = Reflection.getCallerClass(1) == WildFlySecurityManager.class || Reflection.getCallerClass(2) == WildFlySecurityManager.class; | ||
offset = Reflection.getCallerClass(1) == Reflection.class ? 2 : 1; | ||
} catch (Throwable ignored) {} | ||
|
||
JDKSpecific.active = active; | ||
// JDKSpecific.getCallerClass will also add 1 to the stack. | ||
JDKSpecific.offset = offset + 1; | ||
/* | ||
* Using StackWalker the OFFSET is the minimum number of StackFrames, the first will always be | ||
* JDKSpecific,getCallerClass(int), the second will always be the caller of this class. | ||
*/ | ||
private static final int OFFSET = 2; | ||
|
||
public static Class<?> getCallerClass(int n){ | ||
// Although we know WildFlySecurityManager is making the call it may not be the actual SecurityManager | ||
// so we need to use doPrivileged instead of a doUnchecked unless we can be sure checking has been switched off. | ||
final StackWalker stackWalker = WildFlySecurityManager.isChecking() ? | ||
doPrivileged((PrivilegedAction<StackWalker>)JDKSpecific::getStackWalker) : getStackWalker(); | ||
|
||
List<StackWalker.StackFrame> frames = stackWalker.walk(s -> | ||
s.limit(n + OFFSET).collect(Collectors.toList()) | ||
); | ||
return frames.get(frames.size() - 1).getDeclaringClass(); | ||
} | ||
|
||
public static Class<?> getCallerClass(int n) { | ||
if (active) { | ||
return Reflection.getCallerClass(n + offset); | ||
} else { | ||
throw new IllegalStateException("sun.reflect.Reflect.getCallerClass(int) not available."); | ||
} | ||
private static StackWalker getStackWalker() { | ||
return StackWalker.getInstance(Option.RETAIN_CLASS_REFERENCE); | ||
} | ||
|
||
public static boolean usingStackWalker() { | ||
return false; | ||
return true; | ||
} | ||
|
||
} |
59 changes: 0 additions & 59 deletions
59
manager/base/src/main/java9/org/wildfly/security/manager/JDKSpecific.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@cam-rod @fjuma do we have plans for the
JDKSpecific
classes? Can we refactore them out of the codebase? Since they were introduced to resolve some inconsistencies between Java 8 and Java 9 IIUCThere 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.
I don't think there's a specific requirement for those classes, so likely yes
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.
Should I go ahead with refactoring out these classes?