Skip to content

Commit 2c95d4e

Browse files
committed
HV-912 Adding doPrivileged() block around ClassLoader#loadResource() call
1 parent e8c42b6 commit 2c95d4e

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

engine/src/main/java/org/hibernate/validator/internal/util/logging/Messages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public interface Messages {
8484
@Message(value = "The created instance must not be null.", format = Message.Format.NO_FORMAT)
8585
String validatedConstructorCreatedInstanceMustNotBeNull();
8686

87-
@Message(value = "The input stream for #addMappging() cannot be null.")
87+
@Message(value = "The input stream for #addMapping() cannot be null.")
8888
String inputStreamCannotBeNull();
8989
}
9090

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/XmlParserHelper.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

4344
import static org.hibernate.validator.internal.util.logging.Messages.MESSAGES;
4445

@@ -152,7 +153,7 @@ public Schema getSchema(String schemaResource) {
152153
private Schema loadSchema(String schemaResource) {
153154
ClassLoader loader = run( GetClassLoader.fromClass( XmlParserHelper.class ) );
154155

155-
URL schemaUrl = loader.getResource( schemaResource );
156+
URL schemaUrl = run( GetResource.action( loader, schemaResource ) );
156157
SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
157158
Schema schema = null;
158159
try {

0 commit comments

Comments
 (0)