Skip to content

Commit

Permalink
Added doPrivileged for setAccessible when parsing JPQL query with EXT… (
Browse files Browse the repository at this point in the history
eclipse-ee4j#1982)

* Added doPrivileged for setAccessible when parsing JPQL query with EXTRACT and in AbstractStateObject.java and DefaultSemanticValidator.java
  • Loading branch information
ajaypaul-ibm authored Nov 7, 2023
1 parent 8431737 commit 514952e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -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 @@ -244,7 +246,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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -46,6 +46,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 @@ -259,7 +261,9 @@ protected TypeValidator getValidator(Class<? extends TypeValidator> validatorCla
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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -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 @@ -158,7 +160,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 514952e

Please sign in to comment.