diff --git a/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/parser/AbstractExpression.java b/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/parser/AbstractExpression.java index b42b7780770..47fbfa03f75 100644 --- a/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/parser/AbstractExpression.java +++ b/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/parser/AbstractExpression.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2018 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 @@ -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; @@ -245,7 +247,9 @@ protected void acceptUnknownVisitor(ExpressionVisitor visitor, try { Method visitMethod = type.getDeclaredMethod("visit", parameterType); - visitMethod.setAccessible(true); + if (!visitMethod.isAccessible()) { + AccessController.doPrivileged((PrivilegedAction) () -> {visitMethod.setAccessible(true); return null;}); + } visitMethod.invoke(visitor, this); } catch (NoSuchMethodException e) { diff --git a/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/tools/DefaultSemanticValidator.java b/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/tools/DefaultSemanticValidator.java index dfc3a629e84..d0373c92c2e 100644 --- a/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/tools/DefaultSemanticValidator.java +++ b/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/tools/DefaultSemanticValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2018 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 @@ -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; @@ -265,7 +267,9 @@ protected TypeValidator getValidator(Class validatorCla if (validator == null) { try { Constructor constructor = validatorClass.getDeclaredConstructor(DefaultSemanticValidator.class); - constructor.setAccessible(true); + if (!constructor.isAccessible()) { + AccessController.doPrivileged((PrivilegedAction) () -> {constructor.setAccessible(true); return null;}); + } validator = constructor.newInstance(this); validators.put(validatorClass, validator); } diff --git a/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/tools/model/query/AbstractStateObject.java b/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/tools/model/query/AbstractStateObject.java index 2feb9190b44..b5fbade8fdc 100644 --- a/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/tools/model/query/AbstractStateObject.java +++ b/jpa/org.eclipse.persistence.jpa.jpql/src/org/eclipse/persistence/jpa/jpql/tools/model/query/AbstractStateObject.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2018 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 @@ -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; @@ -159,7 +161,9 @@ protected void acceptUnknownVisitor(StateObjectVisitor visitor, try { Method visitMethod = type.getDeclaredMethod("visit", parameterType); - visitMethod.setAccessible(true); + if (!visitMethod.isAccessible()) { + AccessController.doPrivileged((PrivilegedAction) () -> {visitMethod.setAccessible(true); return null;}); + } visitMethod.invoke(visitor, this); } catch (NoSuchMethodException e) {