Skip to content

Commit

Permalink
Added doPrivileged for setAccessible when parsing JPQL query with EX…
Browse files Browse the repository at this point in the history
…TRACT
  • Loading branch information
ajaypaul-ibm authored and lukasj committed Nov 13, 2023
1 parent 7f18d64 commit ed0e575
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
Expand Down Expand Up @@ -236,6 +238,7 @@ protected boolean acceptUnknownVisitor(ExpressionVisitor visitor) {
* @see #acceptUnknownVisitor(ExpressionVisitor)
* @since 2.4
*/
@SuppressWarnings("removal")
protected void acceptUnknownVisitor(ExpressionVisitor visitor,
Class<?> type,
Class<?> parameterType) throws NoSuchMethodException,
Expand All @@ -244,7 +247,9 @@ protected void acceptUnknownVisitor(ExpressionVisitor visitor,

try {
Method visitMethod = type.getDeclaredMethod("visit", parameterType);
visitMethod.setAccessible(true);
if (!visitMethod.canAccess(visitor)) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {visitMethod.setAccessible(true); return null;});
}
visitMethod.invoke(visitor, this);
}
catch (NoSuchMethodException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import static org.eclipse.persistence.jpa.jpql.JPQLQueryProblemMessages.UpperExpression_WrongType;

import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -263,13 +265,15 @@ protected UpdateClauseAbstractSchemaNameFinder getUpdateClauseAbstractSchemaName
}
return updateClauseAbstractSchemaNameFinder;
}

@SuppressWarnings("removal")
protected TypeValidator getValidator(Class<? extends TypeValidator> validatorClass) {
TypeValidator validator = validators.get(validatorClass);
if (validator == null) {
try {
Constructor<? extends TypeValidator> constructor = validatorClass.getDeclaredConstructor(DefaultSemanticValidator.class);
constructor.setAccessible(true);
if (!constructor.canAccess(null)) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {constructor.setAccessible(true); return null;});
}
validator = constructor.newInstance(this);
validators.put(validatorClass, validator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -150,6 +152,7 @@ protected boolean acceptUnknownVisitor(StateObjectVisitor visitor) {
* @see #acceptUnknownVisitor(StateObjectVisitor)
* @since 2.4
*/
@SuppressWarnings("removal")
protected void acceptUnknownVisitor(StateObjectVisitor visitor,
Class<?> type,
Class<?> parameterType) throws NoSuchMethodException,
Expand All @@ -158,7 +161,9 @@ protected void acceptUnknownVisitor(StateObjectVisitor visitor,

try {
Method visitMethod = type.getDeclaredMethod("visit", parameterType);
visitMethod.setAccessible(true);
if (!visitMethod.canAccess(visitor)) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {visitMethod.setAccessible(true); return null;});
}
visitMethod.invoke(visitor, this);
}
catch (NoSuchMethodException e) {
Expand Down

0 comments on commit ed0e575

Please sign in to comment.