From e59d080f55f23a208ffbf394a4096c5c43062b90 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Mon, 21 Jul 2014 17:25:52 +0200 Subject: [PATCH] HV-912 Adding doPrivileged() block around ClassLoader#loadResource() call --- .../metadata/raw/ConstrainedMethod.java | 4 -- .../annotationfactory/AnnotationProxy.java | 32 ------------- .../util/privilegedactions/GetResource.java | 47 +++++++++++++++++++ .../internal/xml/ValidationXmlParser.java | 3 +- .../internal/xml/XmlMappingParser.java | 3 +- 5 files changed, 51 insertions(+), 38 deletions(-) create mode 100644 engine/src/main/java/org/hibernate/validator/internal/util/privilegedactions/GetResource.java diff --git a/engine/src/main/java/org/hibernate/validator/internal/metadata/raw/ConstrainedMethod.java b/engine/src/main/java/org/hibernate/validator/internal/metadata/raw/ConstrainedMethod.java index 0abebb1d58..58e24cc861 100644 --- a/engine/src/main/java/org/hibernate/validator/internal/metadata/raw/ConstrainedMethod.java +++ b/engine/src/main/java/org/hibernate/validator/internal/metadata/raw/ConstrainedMethod.java @@ -114,10 +114,6 @@ public ConstrainedMethod( this.parameterMetaData = Collections.unmodifiableList( parameterMetaData ); this.hasParameterConstraints = hasParameterConstraints( parameterMetaData ); - - if ( isConstrained() ) { - run( SetAccessibility.action( method ) ); - } } private boolean hasParameterConstraints(List parameterMetaData) { diff --git a/engine/src/main/java/org/hibernate/validator/internal/util/annotationfactory/AnnotationProxy.java b/engine/src/main/java/org/hibernate/validator/internal/util/annotationfactory/AnnotationProxy.java index fdbf4ca937..e12d70841c 100644 --- a/engine/src/main/java/org/hibernate/validator/internal/util/annotationfactory/AnnotationProxy.java +++ b/engine/src/main/java/org/hibernate/validator/internal/util/annotationfactory/AnnotationProxy.java @@ -134,38 +134,6 @@ private SortedSet getRegisteredMethodsInAlphabeticalOrder() { return result; } - private boolean areEqual(Object o1, Object o2) { - return - !o1.getClass().isArray() ? o1.equals( o2 ) : - o1.getClass() == boolean[].class ? Arrays.equals( (boolean[]) o1, (boolean[]) o2 ) : - o1.getClass() == byte[].class ? Arrays.equals( (byte[]) o1, (byte[]) o2 ) : - o1.getClass() == char[].class ? Arrays.equals( (char[]) o1, (char[]) o2 ) : - o1.getClass() == double[].class ? Arrays.equals( - (double[]) o1, - (double[]) o2 - ) : - o1.getClass() == float[].class ? Arrays.equals( - (float[]) o1, - (float[]) o2 - ) : - o1.getClass() == int[].class ? Arrays.equals( - (int[]) o1, - (int[]) o2 - ) : - o1.getClass() == long[].class ? Arrays.equals( - (long[]) o1, - (long[]) o2 - ) : - o1.getClass() == short[].class ? Arrays.equals( - (short[]) o1, - (short[]) o2 - ) : - Arrays.equals( - (Object[]) o1, - (Object[]) o2 - ); - } - /** * Runs the given privileged action, using a privileged block if required. *

diff --git a/engine/src/main/java/org/hibernate/validator/internal/util/privilegedactions/GetResource.java b/engine/src/main/java/org/hibernate/validator/internal/util/privilegedactions/GetResource.java new file mode 100644 index 0000000000..268b5073a5 --- /dev/null +++ b/engine/src/main/java/org/hibernate/validator/internal/util/privilegedactions/GetResource.java @@ -0,0 +1,47 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package org.hibernate.validator.internal.util.privilegedactions; + +import java.net.URL; +import java.security.PrivilegedAction; + +/** + * Loads the given resource. + * + * @author Gunnar Morling + */ +public final class GetResource implements PrivilegedAction { + + private final String resourceName; + private final ClassLoader classLoader; + + public static GetResource action(ClassLoader classLoader, String resourceName) { + return new GetResource( classLoader, resourceName ); + } + + private GetResource(ClassLoader classLoader, String resourceName) { + this.classLoader = classLoader; + this.resourceName = resourceName; + } + + @Override + public URL run() { + return classLoader.getResource( resourceName ); + } +} diff --git a/engine/src/main/java/org/hibernate/validator/internal/xml/ValidationXmlParser.java b/engine/src/main/java/org/hibernate/validator/internal/xml/ValidationXmlParser.java index c1ef8c1d94..af444758b2 100644 --- a/engine/src/main/java/org/hibernate/validator/internal/xml/ValidationXmlParser.java +++ b/engine/src/main/java/org/hibernate/validator/internal/xml/ValidationXmlParser.java @@ -39,6 +39,7 @@ import org.hibernate.validator.internal.util.logging.Log; import org.hibernate.validator.internal.util.logging.LoggerFactory; import org.hibernate.validator.internal.util.privilegedactions.GetClassLoader; +import org.hibernate.validator.internal.util.privilegedactions.GetResource; import org.hibernate.validator.internal.util.privilegedactions.LoadClass; import org.hibernate.validator.internal.util.privilegedactions.NewInstance; @@ -246,7 +247,7 @@ private InputStream getInputStreamForPath(String path) { private Schema getValidationConfigurationSchema() { ClassLoader loader = run( GetClassLoader.fromClass( ValidationXmlParser.class ) ); - URL schemaUrl = loader.getResource( VALIDATION_CONFIGURATION_XSD ); + URL schemaUrl = run( GetResource.action( loader, VALIDATION_CONFIGURATION_XSD ) ); SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI ); Schema schema = null; try { diff --git a/engine/src/main/java/org/hibernate/validator/internal/xml/XmlMappingParser.java b/engine/src/main/java/org/hibernate/validator/internal/xml/XmlMappingParser.java index e1ac7dc035..e0c8d9d74d 100644 --- a/engine/src/main/java/org/hibernate/validator/internal/xml/XmlMappingParser.java +++ b/engine/src/main/java/org/hibernate/validator/internal/xml/XmlMappingParser.java @@ -60,6 +60,7 @@ import org.hibernate.validator.internal.util.privilegedactions.GetDeclaredField; import org.hibernate.validator.internal.util.privilegedactions.GetMethod; import org.hibernate.validator.internal.util.privilegedactions.GetMethodFromPropertyName; +import org.hibernate.validator.internal.util.privilegedactions.GetResource; import org.hibernate.validator.internal.util.privilegedactions.LoadClass; import static org.hibernate.validator.internal.util.CollectionHelper.newArrayList; @@ -602,7 +603,7 @@ private boolean isQualifiedClass(String clazz) { private Schema getMappingSchema() { ClassLoader loader = run( GetClassLoader.fromClass( XmlMappingParser.class ) ); - URL schemaUrl = loader.getResource( VALIDATION_MAPPING_XSD ); + URL schemaUrl = run( GetResource.action( loader, VALIDATION_MAPPING_XSD ) ); SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI ); Schema schema = null; try {