Skip to content

Commit e59d080

Browse files
gunnarmorlinghferentschik
authored andcommitted
HV-912 Adding doPrivileged() block around ClassLoader#loadResource() call
1 parent 7796507 commit e59d080

File tree

5 files changed

+51
-38
lines changed

5 files changed

+51
-38
lines changed

engine/src/main/java/org/hibernate/validator/internal/metadata/raw/ConstrainedMethod.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ public ConstrainedMethod(
114114

115115
this.parameterMetaData = Collections.unmodifiableList( parameterMetaData );
116116
this.hasParameterConstraints = hasParameterConstraints( parameterMetaData );
117-
118-
if ( isConstrained() ) {
119-
run( SetAccessibility.action( method ) );
120-
}
121117
}
122118

123119
private boolean hasParameterConstraints(List<ConstrainedParameter> parameterMetaData) {

engine/src/main/java/org/hibernate/validator/internal/util/annotationfactory/AnnotationProxy.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -134,38 +134,6 @@ private SortedSet<String> getRegisteredMethodsInAlphabeticalOrder() {
134134
return result;
135135
}
136136

137-
private boolean areEqual(Object o1, Object o2) {
138-
return
139-
!o1.getClass().isArray() ? o1.equals( o2 ) :
140-
o1.getClass() == boolean[].class ? Arrays.equals( (boolean[]) o1, (boolean[]) o2 ) :
141-
o1.getClass() == byte[].class ? Arrays.equals( (byte[]) o1, (byte[]) o2 ) :
142-
o1.getClass() == char[].class ? Arrays.equals( (char[]) o1, (char[]) o2 ) :
143-
o1.getClass() == double[].class ? Arrays.equals(
144-
(double[]) o1,
145-
(double[]) o2
146-
) :
147-
o1.getClass() == float[].class ? Arrays.equals(
148-
(float[]) o1,
149-
(float[]) o2
150-
) :
151-
o1.getClass() == int[].class ? Arrays.equals(
152-
(int[]) o1,
153-
(int[]) o2
154-
) :
155-
o1.getClass() == long[].class ? Arrays.equals(
156-
(long[]) o1,
157-
(long[]) o2
158-
) :
159-
o1.getClass() == short[].class ? Arrays.equals(
160-
(short[]) o1,
161-
(short[]) o2
162-
) :
163-
Arrays.equals(
164-
(Object[]) o1,
165-
(Object[]) o2
166-
);
167-
}
168-
169137
/**
170138
* Runs the given privileged action, using a privileged block if required.
171139
* <p>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
package org.hibernate.validator.internal.util.privilegedactions;
20+
21+
import java.net.URL;
22+
import java.security.PrivilegedAction;
23+
24+
/**
25+
* Loads the given resource.
26+
*
27+
* @author Gunnar Morling
28+
*/
29+
public final class GetResource implements PrivilegedAction<URL> {
30+
31+
private final String resourceName;
32+
private final ClassLoader classLoader;
33+
34+
public static GetResource action(ClassLoader classLoader, String resourceName) {
35+
return new GetResource( classLoader, resourceName );
36+
}
37+
38+
private GetResource(ClassLoader classLoader, String resourceName) {
39+
this.classLoader = classLoader;
40+
this.resourceName = resourceName;
41+
}
42+
43+
@Override
44+
public URL run() {
45+
return classLoader.getResource( resourceName );
46+
}
47+
}

engine/src/main/java/org/hibernate/validator/internal/xml/ValidationXmlParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.hibernate.validator.internal.util.logging.Log;
4040
import org.hibernate.validator.internal.util.logging.LoggerFactory;
4141
import org.hibernate.validator.internal.util.privilegedactions.GetClassLoader;
42+
import org.hibernate.validator.internal.util.privilegedactions.GetResource;
4243
import org.hibernate.validator.internal.util.privilegedactions.LoadClass;
4344
import org.hibernate.validator.internal.util.privilegedactions.NewInstance;
4445

@@ -246,7 +247,7 @@ private InputStream getInputStreamForPath(String path) {
246247

247248
private Schema getValidationConfigurationSchema() {
248249
ClassLoader loader = run( GetClassLoader.fromClass( ValidationXmlParser.class ) );
249-
URL schemaUrl = loader.getResource( VALIDATION_CONFIGURATION_XSD );
250+
URL schemaUrl = run( GetResource.action( loader, VALIDATION_CONFIGURATION_XSD ) );
250251
SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
251252
Schema schema = null;
252253
try {

engine/src/main/java/org/hibernate/validator/internal/xml/XmlMappingParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.hibernate.validator.internal.util.privilegedactions.GetDeclaredField;
6161
import org.hibernate.validator.internal.util.privilegedactions.GetMethod;
6262
import org.hibernate.validator.internal.util.privilegedactions.GetMethodFromPropertyName;
63+
import org.hibernate.validator.internal.util.privilegedactions.GetResource;
6364
import org.hibernate.validator.internal.util.privilegedactions.LoadClass;
6465

6566
import static org.hibernate.validator.internal.util.CollectionHelper.newArrayList;
@@ -602,7 +603,7 @@ private boolean isQualifiedClass(String clazz) {
602603

603604
private Schema getMappingSchema() {
604605
ClassLoader loader = run( GetClassLoader.fromClass( XmlMappingParser.class ) );
605-
URL schemaUrl = loader.getResource( VALIDATION_MAPPING_XSD );
606+
URL schemaUrl = run( GetResource.action( loader, VALIDATION_MAPPING_XSD ) );
606607
SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
607608
Schema schema = null;
608609
try {

0 commit comments

Comments
 (0)