[java-support] branch master updated: Null-related corrections, tweaks, and cleanup.
Scott Cantor
cantor.2 at osu.edu
Wed Oct 24 14:33:50 EDT 2018
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-support.
View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=1b1389160c2fa56ba0f734ca3391dbf94cb187b1
The following commit(s) were added to refs/heads/master by this push:
new 1b13891 Null-related corrections, tweaks, and cleanup.
1b13891 is described below
commit 1b1389160c2fa56ba0f734ca3391dbf94cb187b1
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Oct 24 14:33:47 2018 -0400
Null-related corrections, tweaks, and cleanup.
---
.../java/support/codec/Base32Support.java | 12 ++--
.../java/support/codec/Base64Support.java | 12 ++--
.../utilities/java/support/codec/HTMLEncoder.java | 12 ++--
.../java/support/collection/ClassIndexedSet.java | 2 +-
.../collection/ClassToInstanceMultiMap.java | 23 +++----
.../LockableClassToInstanceMultiMap.java | 2 +-
.../utilities/java/support/collection/Pair.java | 5 +-
.../java/support/httpclient/HttpClientBuilder.java | 71 +++++++++++-----------
.../java/support/httpclient/TLSSocketFactory.java | 49 ++++++++-------
.../support/logic/TrimOrNullStringFunction.java | 6 +-
.../utilities/java/support/net/CookieManager.java | 14 +----
.../java/support/net/SimpleURLCanonicalizer.java | 10 ++-
.../java/support/primitive/LangBearingString.java | 2 +-
.../support/primitive/LazilyFormattedString.java | 2 +
.../java/support/primitive/TimerSupport.java | 16 ++++-
.../java/support/scripting/EvaluableScript.java | 20 +++---
.../java/support/scripting/ScriptedRunnable.java | 3 +-
.../security/BasicAccessControlService.java | 4 +-
.../java/support/security/DataSealer.java | 6 +-
.../FixedStringIdentifierGenerationStrategy.java | 15 ++---
.../security/IdentifierGenerationStrategy.java | 6 +-
.../RandomIdentifierGenerationStrategy.java | 5 +-
.../security/SelfSignedCertificateGenerator.java | 2 +-
.../Type4UUIDIdentifierGenerationStrategy.java | 6 +-
.../java/support/xml/AttributeSupport.java | 2 +-
.../java/support/xml/NamespaceSupport.java | 25 +++++---
.../utilities/java/support/xml/SchemaBuilder.java | 4 +-
.../java/support/xml/SimpleNamespaceContext.java | 4 +-
...stractIdentifiedInitializableComponentTest.java | 7 ++-
.../support/component/ComponentSupportTest.java | 10 ++-
.../logic/TransformAndCheckFunctionTest.java | 11 ++--
.../java/support/primitive/StringSupportTest.java | 27 +++++---
.../support/resource/TestResourceConverter.java | 2 +-
.../support/scripting/EvaluableScriptTest.java | 19 ++++--
.../java/support/security/DataSealerTest.java | 12 +++-
.../java/support/xml/AttributeSupportTest.java | 56 +++++++++--------
.../java/support/xml/BasicParserPoolTest.java | 18 +++---
.../java/support/xml/ElementSupportTest.java | 39 +++++++-----
.../java/support/xml/QNameSupportTest.java | 28 +++++----
39 files changed, 330 insertions(+), 239 deletions(-)
diff --git a/src/main/java/net/shibboleth/utilities/java/support/codec/Base32Support.java b/src/main/java/net/shibboleth/utilities/java/support/codec/Base32Support.java
index aafcf00..3366634 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/codec/Base32Support.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/codec/Base32Support.java
@@ -42,10 +42,10 @@ public final class Base32Support {
public static final boolean UNCHUNKED = false;
/** Encoder used to produce chunked output. */
- private static final Base32 CHUNKED_ENCODER = new Base32(76, new byte[] { '\n' });
+ @Nonnull private static final Base32 CHUNKED_ENCODER = new Base32(76, new byte[] { '\n' });
/** Encoder used to produce unchunked output. */
- private static final Base32 UNCHUNKED_ENCODER = new Base32(0, new byte[] { '\n' });
+ @Nonnull private static final Base32 UNCHUNKED_ENCODER = new Base32(0, new byte[] { '\n' });
/** Constructor. */
private Base32Support() {
@@ -63,9 +63,11 @@ public final class Base32Support {
@Nonnull public static String encode(@Nonnull final byte[] data, final boolean chunked) {
Constraint.isNotNull(data, "Binary data to be encoded can not be null");
if (chunked) {
- return StringSupport.trim(CHUNKED_ENCODER.encodeToString(data));
+ return Constraint.isNotNull(StringSupport.trim(CHUNKED_ENCODER.encodeToString(data)),
+ "Encoded data was null");
} else {
- return StringSupport.trim(UNCHUNKED_ENCODER.encodeToString(data));
+ return Constraint.isNotNull(StringSupport.trim(UNCHUNKED_ENCODER.encodeToString(data)),
+ "Encoded data was null");
}
}
@@ -78,6 +80,6 @@ public final class Base32Support {
*/
@Nonnull public static byte[] decode(@Nonnull final String data) {
Constraint.isNotNull(data, "Base32 encoded data cannot be null");
- return CHUNKED_ENCODER.decode(data);
+ return Constraint.isNotNull(CHUNKED_ENCODER.decode(data), "Decoded data was null");
}
}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/utilities/java/support/codec/Base64Support.java b/src/main/java/net/shibboleth/utilities/java/support/codec/Base64Support.java
index eedfbb2..ecd91e6 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/codec/Base64Support.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/codec/Base64Support.java
@@ -42,10 +42,10 @@ public final class Base64Support {
public static final boolean UNCHUNKED = false;
/** Encoder used to produce chunked output. */
- private static final Base64 CHUNKED_ENCODER = new Base64(76, new byte[] { '\n' });
+ @Nonnull private static final Base64 CHUNKED_ENCODER = new Base64(76, new byte[] { '\n' });
/** Encoder used to produce unchunked output. */
- private static final Base64 UNCHUNKED_ENCODER = new Base64(0, new byte[] { '\n' });
+ @Nonnull private static final Base64 UNCHUNKED_ENCODER = new Base64(0, new byte[] { '\n' });
/** Constructor. */
private Base64Support() {
@@ -63,9 +63,11 @@ public final class Base64Support {
@Nonnull public static String encode(@Nonnull final byte[] data, final boolean chunked) {
Constraint.isNotNull(data, "Binary data to be encoded can not be null");
if (chunked) {
- return StringSupport.trim(CHUNKED_ENCODER.encodeToString(data));
+ return Constraint.isNotNull(StringSupport.trim(CHUNKED_ENCODER.encodeToString(data)),
+ "Encoded data was null");
} else {
- return StringSupport.trim(UNCHUNKED_ENCODER.encodeToString(data));
+ return Constraint.isNotNull(StringSupport.trim(UNCHUNKED_ENCODER.encodeToString(data)),
+ "Encoded data was null");
}
}
@@ -78,6 +80,6 @@ public final class Base64Support {
*/
@Nonnull public static byte[] decode(@Nonnull final String data) {
Constraint.isNotNull(data, "Base64 encoded data can not be null");
- return CHUNKED_ENCODER.decode(data);
+ return Constraint.isNotNull(CHUNKED_ENCODER.decode(data), "Decoded data was null");
}
}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/utilities/java/support/codec/HTMLEncoder.java b/src/main/java/net/shibboleth/utilities/java/support/codec/HTMLEncoder.java
index b75d321..4b4d8ed 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/codec/HTMLEncoder.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/codec/HTMLEncoder.java
@@ -44,8 +44,6 @@ import javax.annotation.Nullable;
* An HTML encoder derived from the OWASP ESAPI project. The encoded output will be safe for an HTML interpreter as
* unsafe characters are translated into their safe equivalent.
*
- *
- *
* @see <a href="https://issues.shibboleth.net/jira/browse/OSJ-69">OSJ-69</a>
*
* @see <code>org.owasp.esapi.Encoder</code>
@@ -61,7 +59,7 @@ public final class HTMLEncoder {
@Nonnull public static final char[] IMMUNE_HTMLATTR = {',', '.', '-', '_'};
/** Character to replace illegal characters. */
- @Nonnull public static final char REPLACEMENT_CHAR = '\ufffd';
+ public static final char REPLACEMENT_CHAR = '\ufffd';
/** Hex to replace illegal characters. */
@Nonnull public static final String REPLACEMENT_HEX = "fffd";
@@ -149,9 +147,9 @@ public final class HTMLEncoder {
* @param toEncode the character to encode
* @return the encoded character
*/
- @Nonnull private static String encodeCharacter(@Nonnull final char[] immune, @Nonnull final Character toEncode) {
+ @Nonnull private static String encodeCharacter(@Nonnull final char[] immune, final char toEncode) {
- Character c = toEncode;
+ char c = toEncode;
// check for immune characters
if (containsCharacter(c, immune)) {
@@ -187,7 +185,7 @@ public final class HTMLEncoder {
* @param c the character to lookup.
* @return null if alphanumeric or the character code in hex.
*/
- @Nonnull private static String getHexForNonAlphanumeric(@Nonnull final char c) {
+ @Nullable private static String getHexForNonAlphanumeric(final char c) {
if (c < 0xFF) {
return HEX[c];
}
@@ -201,7 +199,7 @@ public final class HTMLEncoder {
* @param array the array
* @return whether or not the array contains the char
*/
- private static boolean containsCharacter(@Nonnull final char c, @Nonnull final char[] array) {
+ private static boolean containsCharacter(final char c, @Nonnull final char[] array) {
for (final char ch : array) {
if (c == ch) {
return true;
diff --git a/src/main/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSet.java b/src/main/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSet.java
index b86a13e..0eb1ed3 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSet.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/collection/ClassIndexedSet.java
@@ -52,7 +52,7 @@ public class ClassIndexedSet<T> extends AbstractSet<T> implements Set<T> {
}
/** {@inheritDoc} */
- public boolean add(@Nonnull final T o) {
+ public boolean add(final T o) {
return add(o, false);
}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java b/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java
index 729f084..eaed26e 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/collection/ClassToInstanceMultiMap.java
@@ -20,6 +20,7 @@ package net.shibboleth.utilities.java.support.collection;
import net.shibboleth.utilities.java.support.annotation.constraint.Live;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
+import net.shibboleth.utilities.java.support.logic.Constraint;
import java.util.ArrayList;
import java.util.Collection;
@@ -92,13 +93,13 @@ public class ClassToInstanceMultiMap<B> {
}
/**
- * Returns true if the map contains a mapping to the given value.
+ * Returns true iff the map contains a mapping to the given value, false if value is null.
*
* @param value value to check for in this map
*
- * @return true if the map contains a mapping to the specified value
+ * @return true iff the map contains a mapping to the specified value
*/
- public boolean containsValue(@Nonnull final B value) {
+ public boolean containsValue(@Nullable final B value) {
if (value == null) {
return false;
}
@@ -156,9 +157,7 @@ public class ClassToInstanceMultiMap<B> {
* @param value value to be stored in the map
*/
public void put(@Nonnull final B value) {
- if (value == null) {
- return;
- }
+ Constraint.isNotNull(value, "Value cannot be null");
if (!values.contains(value)) {
values.add(value);
@@ -223,18 +222,16 @@ public class ClassToInstanceMultiMap<B> {
*
* @param value the value to remove
*/
- public void remove(@Nonnull final B value) {
- if (value == null) {
- return;
- }
+ public void remove(@Nullable final B value) {
+ final B checked = Constraint.isNotNull(value, "Value cannot be null");
- values.remove(value);
+ values.remove(checked);
List<B> indexValues;
- for (final Class<?> indexKey : getIndexTypes(value)) {
+ for (final Class<?> indexKey : getIndexTypes(checked)) {
indexValues = backingMap.get(indexKey);
if (indexValues != null) {
- indexValues.remove(value);
+ indexValues.remove(checked);
if (indexValues.isEmpty()) {
backingMap.remove(indexKey);
}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/collection/LockableClassToInstanceMultiMap.java b/src/main/java/net/shibboleth/utilities/java/support/collection/LockableClassToInstanceMultiMap.java
index 628da0f..38fcd0c 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/collection/LockableClassToInstanceMultiMap.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/collection/LockableClassToInstanceMultiMap.java
@@ -121,7 +121,7 @@ public class LockableClassToInstanceMultiMap<B> extends ClassToInstanceMultiMap<
*
* @return true if the map contains a mapping to the specified value
*/
- public boolean containsValueWithLock(@Nonnull final B value) {
+ public boolean containsValueWithLock(@Nullable final B value) {
final Lock readLock = getReadWriteLock().readLock();
try {
readLock.lock();
diff --git a/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java b/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java
index 0b70932..481a472 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/collection/Pair.java
@@ -103,6 +103,7 @@ public class Pair<T1, T2> {
}
/** {@inheritDoc} */
+ @Override
public boolean equals(@Nullable final Object o) {
if (o == this) {
return true;
@@ -118,12 +119,14 @@ public class Pair<T1, T2> {
}
/** {@inheritDoc} */
+ @Override
public int hashCode() {
return Objects.hashCode(first, second);
}
/** {@inheritDoc} */
- @Nonnull public String toString() {
+ @Override
+ public String toString() {
return MoreObjects.toStringHelper(this).add("first", first).add("second", second).toString();
}
}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/utilities/java/support/httpclient/HttpClientBuilder.java b/src/main/java/net/shibboleth/utilities/java/support/httpclient/HttpClientBuilder.java
index 500e742..7237cbb 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/httpclient/HttpClientBuilder.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/httpclient/HttpClientBuilder.java
@@ -20,6 +20,7 @@ package net.shibboleth.utilities.java.support.httpclient;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
@@ -44,6 +45,9 @@ import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import net.shibboleth.utilities.java.support.annotation.Duration;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotLive;
+import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
import net.shibboleth.utilities.java.support.collection.IterableSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
@@ -240,16 +244,16 @@ public class HttpClientBuilder {
private boolean useSystemProperties;
/** List of request interceptors to add first. */
- private List<HttpRequestInterceptor> requestInterceptorsFirst;
+ @Nonnull @NonnullElements private List<HttpRequestInterceptor> requestInterceptorsFirst;
/** List of request interceptors to add last. */
- private List<HttpRequestInterceptor> requestInterceptorsLast;
+ @Nonnull @NonnullElements private List<HttpRequestInterceptor> requestInterceptorsLast;
/** List of response interceptors to add first. */
- private List<HttpResponseInterceptor> responseInterceptorsFirst;
+ @Nonnull @NonnullElements private List<HttpResponseInterceptor> responseInterceptorsFirst;
/** List of response interceptors to add last. */
- private List<HttpResponseInterceptor> responseInterceptorsLast;
+ @Nonnull @NonnullElements private List<HttpResponseInterceptor> responseInterceptorsLast;
/** The Apache HttpClientBuilder 4.3+ instance over which to layer this builder. */
private org.apache.http.impl.client.HttpClientBuilder apacheBuilder;
@@ -265,9 +269,12 @@ public class HttpClientBuilder {
* @param builder the Apache HttpClientBuilder 4.3+ instance over which to layer this builder
*/
public HttpClientBuilder(@Nonnull final org.apache.http.impl.client.HttpClientBuilder builder) {
- Constraint.isNotNull(builder, "Apache HttpClientBuilder may not be null");
- apacheBuilder = builder;
+ apacheBuilder = Constraint.isNotNull(builder, "Apache HttpClientBuilder may not be null");
resetDefaults();
+ requestInterceptorsFirst = Collections.emptyList();
+ requestInterceptorsLast = Collections.emptyList();
+ responseInterceptorsFirst = Collections.emptyList();
+ responseInterceptorsLast = Collections.emptyList();
}
/** Resets all builder parameters to their defaults. */
@@ -851,7 +858,7 @@ public class HttpClientBuilder {
*
* @return the list of interceptors, may be null
*/
- @Nullable public List<HttpRequestInterceptor> getFirstRequestInterceptors() {
+ @Nonnull @NonnullElements @NotLive @Unmodifiable public List<HttpRequestInterceptor> getFirstRequestInterceptors() {
return requestInterceptorsFirst;
}
@@ -869,7 +876,7 @@ public class HttpClientBuilder {
*
* @return the list of interceptors, may be null
*/
- @Nullable public List<HttpRequestInterceptor> getLastRequestInterceptors() {
+ @Nonnull @NonnullElements @NotLive @Unmodifiable public List<HttpRequestInterceptor> getLastRequestInterceptors() {
return requestInterceptorsLast;
}
@@ -878,7 +885,7 @@ public class HttpClientBuilder {
*
* @param interceptors the list of interceptors, may be null
*/
- public void setLastRequestInterceptors(final List<HttpRequestInterceptor> interceptors) {
+ public void setLastRequestInterceptors(@Nullable final List<HttpRequestInterceptor> interceptors) {
requestInterceptorsLast = normalizeInterceptors(interceptors);
}
@@ -887,7 +894,8 @@ public class HttpClientBuilder {
*
* @return the list of interceptors, may be null
*/
- @Nullable public List<HttpResponseInterceptor> getFirstResponseInterceptors() {
+ @Nonnull @NonnullElements @NotLive @Unmodifiable
+ public List<HttpResponseInterceptor> getFirstResponseInterceptors() {
return responseInterceptorsFirst;
}
@@ -896,7 +904,7 @@ public class HttpClientBuilder {
*
* @param interceptors the list of interceptors, may be null
*/
- public void setFirstResponseInterceptors(final List<HttpResponseInterceptor> interceptors) {
+ public void setFirstResponseInterceptors(@Nullable final List<HttpResponseInterceptor> interceptors) {
responseInterceptorsFirst = normalizeInterceptors(interceptors);
}
@@ -905,7 +913,8 @@ public class HttpClientBuilder {
*
* @return the list of interceptors, may be null
*/
- @Nullable public List<HttpResponseInterceptor> getLastResponseInterceptors() {
+ @Nonnull @NonnullElements @NotLive @Unmodifiable
+ public List<HttpResponseInterceptor> getLastResponseInterceptors() {
return responseInterceptorsLast;
}
@@ -914,7 +923,7 @@ public class HttpClientBuilder {
*
* @param interceptors the list of interceptors, may be null
*/
- public void setLastResponseInterceptors(final List<HttpResponseInterceptor> interceptors) {
+ public void setLastResponseInterceptors(@Nullable final List<HttpResponseInterceptor> interceptors) {
responseInterceptorsLast = normalizeInterceptors(interceptors);
}
@@ -926,9 +935,9 @@ public class HttpClientBuilder {
* @param interceptors the list of interceptors to normalize
* @return copy of input list without nulls, may be null
*/
- @Nullable private <T> List<T> normalizeInterceptors(@Nullable final List<T> interceptors) {
+ @Nonnull @NonnullElements private <T> List<T> normalizeInterceptors(@Nullable final List<T> interceptors) {
if (interceptors == null) {
- return null;
+ return Collections.emptyList();
} else {
return new ArrayList<>(Collections2.filter(interceptors, Predicates.notNull()));
}
@@ -965,11 +974,8 @@ public class HttpClientBuilder {
}
if (connectionCloseAfterResponse) {
- if ((getFirstRequestInterceptors() == null
- || !IterableSupport.containsInstance(getFirstRequestInterceptors(), RequestConnectionClose.class))
- &&
- (getLastRequestInterceptors() == null
- || !IterableSupport.containsInstance(getLastRequestInterceptors(), RequestConnectionClose.class))) {
+ if (!IterableSupport.containsInstance(getFirstRequestInterceptors(), RequestConnectionClose.class)
+ && !IterableSupport.containsInstance(getLastRequestInterceptors(), RequestConnectionClose.class)) {
builder.addInterceptorLast(new RequestConnectionClose());
}
@@ -1022,31 +1028,22 @@ public class HttpClientBuilder {
builder.useSystemProperties();
}
- if (getFirstRequestInterceptors() != null) {
- for (final HttpRequestInterceptor interceptor : getFirstRequestInterceptors()) {
- builder.addInterceptorFirst(interceptor);
- }
+ for (final HttpRequestInterceptor interceptor : getFirstRequestInterceptors()) {
+ builder.addInterceptorFirst(interceptor);
}
- if (getLastRequestInterceptors() != null) {
- for (final HttpRequestInterceptor interceptor : getLastRequestInterceptors()) {
- builder.addInterceptorLast(interceptor);
- }
+ for (final HttpRequestInterceptor interceptor : getLastRequestInterceptors()) {
+ builder.addInterceptorLast(interceptor);
}
- if (getFirstResponseInterceptors() != null) {
- for (final HttpResponseInterceptor interceptor : getFirstResponseInterceptors()) {
- builder.addInterceptorFirst(interceptor);
- }
+ for (final HttpResponseInterceptor interceptor : getFirstResponseInterceptors()) {
+ builder.addInterceptorFirst(interceptor);
}
- if (getLastResponseInterceptors() != null) {
- for (final HttpResponseInterceptor interceptor : getLastResponseInterceptors()) {
- builder.addInterceptorLast(interceptor);
- }
+ for (final HttpResponseInterceptor interceptor : getLastResponseInterceptors()) {
+ builder.addInterceptorLast(interceptor);
}
-
// RequestConfig params
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
diff --git a/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactory.java b/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactory.java
index 11e136f..7fb8098 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactory.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/httpclient/TLSSocketFactory.java
@@ -34,6 +34,7 @@ import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
import org.apache.http.HttpHost;
@@ -68,41 +69,42 @@ public class TLSSocketFactory implements LayeredConnectionSocketFactory {
/** HttpContext key for a a list of TLS protocols to enable on the socket.
* Must be an instance of {@link List}<{@link String}>. */
- public static final String CONTEXT_KEY_TLS_PROTOCOLS = "javasupport.TLSProtocols";
+ @Nonnull @NotEmpty public static final String CONTEXT_KEY_TLS_PROTOCOLS = "javasupport.TLSProtocols";
/** HttpContext key for a a list of TLS cipher suites to enable on the socket.
* Must be an instance of {@link List}<{@link String}>. */
- public static final String CONTEXT_KEY_TLS_CIPHER_SUITES = "javasupport.TLSCipherSuites";
+ @Nonnull @NotEmpty public static final String CONTEXT_KEY_TLS_CIPHER_SUITES = "javasupport.TLSCipherSuites";
/** HttpContext key for an instance of {@link X509HostnameVerifier}. */
- public static final String CONTEXT_KEY_HOSTNAME_VERIFIER = "javasupport.HostnameVerifier";
+ @Nonnull @NotEmpty public static final String CONTEXT_KEY_HOSTNAME_VERIFIER = "javasupport.HostnameVerifier";
/** Protocol: TLS. */
- public static final String TLS = "TLS";
+ @Nonnull @NotEmpty public static final String TLS = "TLS";
/** Protocol: SSL. */
- public static final String SSL = "SSL";
+ @Nonnull @NotEmpty public static final String SSL = "SSL";
/** Protocol: SSLv2. */
- public static final String SSLV2 = "SSLv2";
+ @Nonnull @NotEmpty public static final String SSLV2 = "SSLv2";
/** Hostname verifier which passes all hostnames. */
- public static final X509HostnameVerifier ALLOW_ALL_HOSTNAME_VERIFIER = new AllowAllHostnameVerifier();
+ @Nonnull public static final X509HostnameVerifier ALLOW_ALL_HOSTNAME_VERIFIER = new AllowAllHostnameVerifier();
/** Hostname verifier which implements a policy similar to most browsers. */
- public static final X509HostnameVerifier BROWSER_COMPATIBLE_HOSTNAME_VERIFIER = new BrowserCompatHostnameVerifier();
+ @Nonnull public static final X509HostnameVerifier BROWSER_COMPATIBLE_HOSTNAME_VERIFIER =
+ new BrowserCompatHostnameVerifier();
/** Hostname verifier which implements a strict policy. */
- public static final X509HostnameVerifier STRICT_HOSTNAME_VERIFIER = new StrictHostnameVerifier();
+ @Nonnull public static final X509HostnameVerifier STRICT_HOSTNAME_VERIFIER = new StrictHostnameVerifier();
/** Logger. */
- private final Logger log = LoggerFactory.getLogger(TLSSocketFactory.class);
+ @Nonnull private final Logger log = LoggerFactory.getLogger(TLSSocketFactory.class);
/** Socket factory. */
- private final SSLSocketFactory socketfactory;
+ @Nonnull private final SSLSocketFactory socketfactory;
/** Hostname verifier. */
- private final X509HostnameVerifier hostnameVerifier;
+ @Nonnull private final X509HostnameVerifier hostnameVerifier;
/** Factory-wide supported protocols. */
private final String[] supportedProtocols;
@@ -129,7 +131,7 @@ public class TLSSocketFactory implements LayeredConnectionSocketFactory {
public TLSSocketFactory(
@Nonnull final SSLContext sslContext,
@Nullable final X509HostnameVerifier verifier) {
- this(Args.notNull(sslContext, "SSL context").getSocketFactory(), null, null, verifier);
+ this(Constraint.isNotNull(sslContext, "SSL context cannot be null").getSocketFactory(), null, null, verifier);
}
/**
@@ -145,7 +147,8 @@ public class TLSSocketFactory implements LayeredConnectionSocketFactory {
@Nullable final String[] protocols,
@Nullable final String[] cipherSuites,
@Nullable final X509HostnameVerifier verifier) {
- this(Args.notNull(sslContext, "SSL context").getSocketFactory(), protocols, cipherSuites, verifier);
+ this(Constraint.isNotNull(sslContext, "SSL context cannot be null").getSocketFactory(),
+ protocols, cipherSuites, verifier);
}
/**
@@ -173,7 +176,7 @@ public class TLSSocketFactory implements LayeredConnectionSocketFactory {
@Nullable final String[] protocols,
@Nullable final String[] cipherSuites,
@Nullable final X509HostnameVerifier verifier) {
- socketfactory = Args.notNull(factory, "SSL socket factory");
+ socketfactory = Constraint.isNotNull(factory, "SSL socket factory cannot be null");
supportedProtocols = protocols;
supportedCipherSuites = cipherSuites;
hostnameVerifier = verifier != null ? verifier : STRICT_HOSTNAME_VERIFIER;
@@ -242,11 +245,11 @@ public class TLSSocketFactory implements LayeredConnectionSocketFactory {
/** {@inheritDoc} */
public Socket connectSocket(
final int connectTimeout,
- @Nullable final Socket socket,
- @Nonnull final HttpHost host,
- @Nonnull final InetSocketAddress remoteAddress,
- @Nullable final InetSocketAddress localAddress,
- @Nullable final HttpContext context) throws IOException {
+ final Socket socket,
+ final HttpHost host,
+ final InetSocketAddress remoteAddress,
+ final InetSocketAddress localAddress,
+ final HttpContext context) throws IOException {
log.trace("In connectSocket");
@@ -283,10 +286,10 @@ public class TLSSocketFactory implements LayeredConnectionSocketFactory {
/** {@inheritDoc} */
public Socket createLayeredSocket(
- @Nonnull final Socket socket,
- @Nonnull @NotEmpty final String target,
+ final Socket socket,
+ final String target,
final int port,
- @Nullable final HttpContext context) throws IOException {
+ final HttpContext context) throws IOException {
log.trace("In createLayeredSocket");
diff --git a/src/main/java/net/shibboleth/utilities/java/support/logic/TrimOrNullStringFunction.java b/src/main/java/net/shibboleth/utilities/java/support/logic/TrimOrNullStringFunction.java
index 325f30f..12c80ad 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/logic/TrimOrNullStringFunction.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/logic/TrimOrNullStringFunction.java
@@ -17,6 +17,7 @@
package net.shibboleth.utilities.java.support.logic;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
@@ -31,7 +32,7 @@ import com.google.common.base.MoreObjects;
public class TrimOrNullStringFunction implements Function<String, String> {
/** A singleton instance of this function. */
- public static final TrimOrNullStringFunction INSTANCE = new TrimOrNullStringFunction();
+ @Nonnull @NotEmpty public static final TrimOrNullStringFunction INSTANCE = new TrimOrNullStringFunction();
/** {@inheritDoc} */
@Nullable @NotEmpty public String apply(@Nullable final String input) {
@@ -39,6 +40,7 @@ public class TrimOrNullStringFunction implements Function<String, String> {
}
/** {@inheritDoc} */
+ @Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
@@ -52,11 +54,13 @@ public class TrimOrNullStringFunction implements Function<String, String> {
}
/** {@inheritDoc} */
+ @Override
public int hashCode() {
return 31;
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return MoreObjects.toStringHelper(this).toString();
}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/net/CookieManager.java b/src/main/java/net/shibboleth/utilities/java/support/net/CookieManager.java
index 0b713ba..6ee7927 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/net/CookieManager.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/net/CookieManager.java
@@ -23,9 +23,6 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
@@ -38,14 +35,11 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
* A helper class for managing one or more cookies on behalf of a component.
*
* <p>This bean centralizes settings related to cookie creation and access,
- * and is parametrized by name so that multiple cookies may be managed with
+ * and is parameterized by name so that multiple cookies may be managed with
* common properties.</p>
*/
public final class CookieManager extends AbstractInitializableComponent {
- /** Class logger. */
- @Nonnull private final Logger log = LoggerFactory.getLogger(CookieManager.class);
-
/** Path of cookie. */
@Nullable private String cookiePath;
@@ -167,8 +161,6 @@ public final class CookieManager extends AbstractInitializableComponent {
if (httpRequest == null || httpResponse == null) {
throw new ComponentInitializationException("Servlet request and response must be set");
- } else if (!secure) {
- log.warn("Use of secure property is strongly advised");
}
}
@@ -178,7 +170,7 @@ public final class CookieManager extends AbstractInitializableComponent {
* @param name name of cookie
* @param value value of cookie
*/
- @Nullable public void addCookie(@Nonnull @NotEmpty final String name, @Nonnull @NotEmpty final String value) {
+ public void addCookie(@Nonnull @NotEmpty final String name, @Nonnull @NotEmpty final String value) {
ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
@@ -199,7 +191,7 @@ public final class CookieManager extends AbstractInitializableComponent {
*
* @param name name of cookie
*/
- @Nullable public void unsetCookie(@Nonnull @NotEmpty final String name) {
+ public void unsetCookie(@Nonnull @NotEmpty final String name) {
ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
diff --git a/src/main/java/net/shibboleth/utilities/java/support/net/SimpleURLCanonicalizer.java b/src/main/java/net/shibboleth/utilities/java/support/net/SimpleURLCanonicalizer.java
index a0352d4..2b5e282 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/net/SimpleURLCanonicalizer.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/net/SimpleURLCanonicalizer.java
@@ -100,7 +100,7 @@ public final class SimpleURLCanonicalizer {
Constraint.isFalse(Strings.isNullOrEmpty(url), "URL was null or empty");
final URLBuilder urlBuilder = new URLBuilder(url);
canonicalize(urlBuilder);
- return urlBuilder.buildURL();
+ return Constraint.isNotEmpty(urlBuilder.buildURL(), "Canonical URL was null");
}
/**
@@ -109,10 +109,14 @@ public final class SimpleURLCanonicalizer {
* @param url the URLBuilder to canonicalize
*/
private static void canonicalize(@Nonnull final URLBuilder url) {
+
+ // Lower case the scheme.
if (url.getScheme() != null) {
url.setScheme(url.getScheme().toLowerCase());
-
- final String scheme = url.getScheme();
+ }
+
+ final String scheme = url.getScheme();
+ if (scheme != null) {
final Integer port = getRegisteredPort(scheme);
if (port != null && port.equals(url.getPort())) {
url.setPort(null);
diff --git a/src/main/java/net/shibboleth/utilities/java/support/primitive/LangBearingString.java b/src/main/java/net/shibboleth/utilities/java/support/primitive/LangBearingString.java
index 07fb82d..5b73d5b 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/primitive/LangBearingString.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/primitive/LangBearingString.java
@@ -73,7 +73,7 @@ public class LangBearingString extends Pair<String,String> {
/** {@inheritDoc} */
@Override
public String toString() {
- return getValue();
+ return super.toString();
}
}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/utilities/java/support/primitive/LazilyFormattedString.java b/src/main/java/net/shibboleth/utilities/java/support/primitive/LazilyFormattedString.java
index 71ee334..7822fe3 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/primitive/LazilyFormattedString.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/primitive/LazilyFormattedString.java
@@ -47,7 +47,9 @@ public class LazilyFormattedString {
}
/** {@inheritDoc} */
+ @Override
public String toString() {
return String.format(template, arguments);
}
+
}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/utilities/java/support/primitive/TimerSupport.java b/src/main/java/net/shibboleth/utilities/java/support/primitive/TimerSupport.java
index 138c927..bfa2bd2 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/primitive/TimerSupport.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/primitive/TimerSupport.java
@@ -81,7 +81,7 @@ public final class TimerSupport {
baseName = obj.getClass().getName();
}
- return getTimerName(baseName, additionalData);
+ return uncheckedGetTimerName(Constraint.isNotNull(baseName, "Base name for Timer was null"), additionalData);
}
/**
@@ -94,11 +94,23 @@ public final class TimerSupport {
@Nonnull @NotEmpty public static String getTimerName(@Nonnull final String baseName,
@Nullable final String additionalData) {
Constraint.isNotNull(baseName, "Base name for Timer was null");
+ return uncheckedGetTimerName(baseName, additionalData);
+ }
+
+ /**
+ * Unchecked version of {@link #getTimerName(String, String)} that assumes base name is non-null.
+ *
+ * @param baseName the base name of Timer
+ * @param additionalData additional qualifying data to include in the name
+ * @return an appropriate name for a Timer based on the specified base name
+ */
+ @Nonnull @NotEmpty private static String uncheckedGetTimerName(@Nonnull final String baseName,
+ @Nullable final String additionalData) {
+
if (additionalData != null) {
return String.format("Timer for %s (%s)", baseName, additionalData);
} else {
return String.format("Timer for %s", baseName);
}
}
-
}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/scripting/EvaluableScript.java b/src/main/java/net/shibboleth/utilities/java/support/scripting/EvaluableScript.java
index 11bcdef..75fdba9 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/scripting/EvaluableScript.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/scripting/EvaluableScript.java
@@ -42,16 +42,16 @@ import com.google.common.io.Files;
public class EvaluableScript {
/** The scripting language. */
- private final String scriptLanguage;
+ @Nonnull @NotEmpty private final String scriptLanguage;
/** The script to execute. */
- private final String script;
+ @Nonnull @NotEmpty private final String script;
/** The script engine to execute the script. */
- private ScriptEngine scriptEngine;
+ @Nullable private ScriptEngine scriptEngine;
/** The compiled form of the script, if the script engine supports compiling. */
- private CompiledScript compiledScript;
+ @Nullable private CompiledScript compiledScript;
/**
* Constructor.
@@ -137,8 +137,8 @@ public class EvaluableScript {
try {
script =
Constraint.isNotNull(
- StringSupport.trimOrNull(Files.toString(scriptSource, Charset.defaultCharset())),
- "Script source can not be empty");
+ StringSupport.trimOrNull(Files.asCharSource(scriptSource, Charset.defaultCharset()).read()),
+ "Script source cannot be empty");
} catch (final IOException e) {
throw new ScriptException("Unable to read data from source file " + scriptSource.getAbsolutePath());
}
@@ -151,7 +151,7 @@ public class EvaluableScript {
*
* @return the script source
*/
- @Nonnull public String getScript() {
+ @Nonnull @NotEmpty public String getScript() {
return script;
}
@@ -160,7 +160,7 @@ public class EvaluableScript {
*
* @return the script source
*/
- @Nonnull public String getScriptLanguage() {
+ @Nonnull @NotEmpty public String getScriptLanguage() {
return scriptLanguage;
}
@@ -173,7 +173,7 @@ public class EvaluableScript {
*
* @throws ScriptException thrown if there was a problem evaluating the script
*/
- @Nullable public Object eval(final Bindings scriptBindings) throws ScriptException {
+ @Nullable public Object eval(@Nonnull final Bindings scriptBindings) throws ScriptException {
if (compiledScript != null) {
return compiledScript.eval(scriptBindings);
} else {
@@ -190,7 +190,7 @@ public class EvaluableScript {
*
* @throws ScriptException thrown if there was a problem evaluating the script
*/
- @Nullable public Object eval(final ScriptContext scriptContext) throws ScriptException {
+ @Nullable public Object eval(@Nonnull final ScriptContext scriptContext) throws ScriptException {
if (compiledScript != null) {
return compiledScript.eval(scriptContext);
} else {
diff --git a/src/main/java/net/shibboleth/utilities/java/support/scripting/ScriptedRunnable.java b/src/main/java/net/shibboleth/utilities/java/support/scripting/ScriptedRunnable.java
index bb434fc..e3b91b2 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/scripting/ScriptedRunnable.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/scripting/ScriptedRunnable.java
@@ -126,7 +126,8 @@ public class ScriptedRunnable extends AbstractIdentifiableInitializableComponent
}
/** {@inheritDoc} */
- @Override protected void prepareContext(final ScriptContext scriptContext, final Object... input) {
+ @Override
+ protected void prepareContext(@Nonnull final ScriptContext scriptContext, @Nullable final Object... input) {
// Nothing to do
}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/security/BasicAccessControlService.java b/src/main/java/net/shibboleth/utilities/java/support/security/BasicAccessControlService.java
index 2844549..a73fdba 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/security/BasicAccessControlService.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/security/BasicAccessControlService.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.servlet.ServletRequest;
import org.slf4j.Logger;
@@ -80,7 +81,8 @@ public class BasicAccessControlService extends AbstractIdentifiableInitializable
getId(), name);
return new AccessControl() {
- public boolean checkAccess(final ServletRequest request, final String operation, final String resource) {
+ public boolean checkAccess(@Nonnull final ServletRequest request, @Nullable final String operation,
+ @Nullable final String resource) {
return false;
}
};
diff --git a/src/main/java/net/shibboleth/utilities/java/support/security/DataSealer.java b/src/main/java/net/shibboleth/utilities/java/support/security/DataSealer.java
index 54495f5..f90ebdd 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/security/DataSealer.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/security/DataSealer.java
@@ -373,8 +373,12 @@ public class DataSealer extends AbstractInitializableComponent {
*
* @throws DataSealerException if the test fails
*/
- private void testEncryption(@Nonnull final SecretKey key) throws DataSealerException {
+ private void testEncryption(@Nullable final SecretKey key) throws DataSealerException {
+ if (key == null) {
+ throw new DataSealerException("Secret key was null");
+ }
+
final String decrypted;
try {
final GCMBlockCipher cipher = new GCMBlockCipher(new AESEngine());
diff --git a/src/main/java/net/shibboleth/utilities/java/support/security/FixedStringIdentifierGenerationStrategy.java b/src/main/java/net/shibboleth/utilities/java/support/security/FixedStringIdentifierGenerationStrategy.java
index aa7a2b2..ff8a5b1 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/security/FixedStringIdentifierGenerationStrategy.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/security/FixedStringIdentifierGenerationStrategy.java
@@ -19,6 +19,7 @@ package net.shibboleth.utilities.java.support.security;
import javax.annotation.Nonnull;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.logic.Constraint;
/**
@@ -30,24 +31,24 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
public class FixedStringIdentifierGenerationStrategy implements IdentifierGenerationStrategy {
/** Fixed identifier to use for all invocations. */
- private final String identifier;
+ @Nonnull @NotEmpty private final String identifier;
/**
* Constructor.
*
* @param id fixed identifier to use for all invocations.
*/
- public FixedStringIdentifierGenerationStrategy(@Nonnull final String id) {
- identifier = Constraint.isNotNull(id, "identifier may not be null");
+ public FixedStringIdentifierGenerationStrategy(@Nonnull @NotEmpty final String id) {
+ identifier = Constraint.isNotEmpty(id, "identifier cannot be null or empty");
}
- @Override
- public String generateIdentifier() {
+ /** {@inheritDoc} */
+ @Nonnull @NotEmpty public String generateIdentifier() {
return identifier;
}
- @Override
- public String generateIdentifier(final boolean xmlSafe) {
+ /** {@inheritDoc} */
+ @Nonnull @NotEmpty public String generateIdentifier(final boolean xmlSafe) {
return identifier;
}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/security/IdentifierGenerationStrategy.java b/src/main/java/net/shibboleth/utilities/java/support/security/IdentifierGenerationStrategy.java
index fe85a52..92142ac 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/security/IdentifierGenerationStrategy.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/security/IdentifierGenerationStrategy.java
@@ -19,6 +19,8 @@ package net.shibboleth.utilities.java.support.security;
import javax.annotation.Nonnull;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+
/**
* Interface for identifier generators. This identifier can be used for things like digital signature identifiers,
* opaque principal identifiers, etc.
@@ -30,7 +32,7 @@ public interface IdentifierGenerationStrategy {
*
* @return the identifier
*/
- @Nonnull public String generateIdentifier();
+ @Nonnull @NotEmpty public String generateIdentifier();
/**
* Generates an identifier.
@@ -38,5 +40,5 @@ public interface IdentifierGenerationStrategy {
* @param xmlSafe true iff the result must be XML ID safe
* @return the identifier
*/
- @Nonnull public String generateIdentifier(boolean xmlSafe);
+ @Nonnull @NotEmpty public String generateIdentifier(boolean xmlSafe);
}
\ No newline at end of file
diff --git a/src/main/java/net/shibboleth/utilities/java/support/security/RandomIdentifierGenerationStrategy.java b/src/main/java/net/shibboleth/utilities/java/support/security/RandomIdentifierGenerationStrategy.java
index a47919f..223600c 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/security/RandomIdentifierGenerationStrategy.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/security/RandomIdentifierGenerationStrategy.java
@@ -23,6 +23,7 @@ import java.util.Random;
import javax.annotation.Nonnull;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.logic.Constraint;
import org.apache.commons.codec.BinaryEncoder;
@@ -94,12 +95,12 @@ public class RandomIdentifierGenerationStrategy implements IdentifierGenerationS
}
/** {@inheritDoc} */
- @Nonnull public String generateIdentifier() {
+ @Nonnull @NotEmpty public String generateIdentifier() {
return generateIdentifier(true);
}
/** {@inheritDoc} */
- public String generateIdentifier(final boolean xmlSafe) {
+ @Nonnull @NotEmpty public String generateIdentifier(final boolean xmlSafe) {
final byte[] buf = new byte[sizeOfIdentifier];
random.nextBytes(buf);
try {
diff --git a/src/main/java/net/shibboleth/utilities/java/support/security/SelfSignedCertificateGenerator.java b/src/main/java/net/shibboleth/utilities/java/support/security/SelfSignedCertificateGenerator.java
index 17efb81..4ec0628 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/security/SelfSignedCertificateGenerator.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/security/SelfSignedCertificateGenerator.java
@@ -458,7 +458,7 @@ public class SelfSignedCertificateGenerator {
/** Hostname. */
@Parameter(names = HOSTNAME, required = true, description = "Hostname for certificate subject")
- @Nonnull @NotEmpty private String hostname;
+ @Nullable @NotEmpty private String hostname;
/** DNS subjectAltNames. */
@Parameter(names = DNS_ALTNAMES, description = "DNS subjectAltNames for certificate")
diff --git a/src/main/java/net/shibboleth/utilities/java/support/security/Type4UUIDIdentifierGenerationStrategy.java b/src/main/java/net/shibboleth/utilities/java/support/security/Type4UUIDIdentifierGenerationStrategy.java
index 29f27e8..a831a69 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/security/Type4UUIDIdentifierGenerationStrategy.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/security/Type4UUIDIdentifierGenerationStrategy.java
@@ -22,17 +22,19 @@ import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+
/** Generates a type 4 UUID as an identifier. */
@ThreadSafe
public class Type4UUIDIdentifierGenerationStrategy implements IdentifierGenerationStrategy {
/** {@inheritDoc} */
- @Nonnull public String generateIdentifier() {
+ @Nonnull @NotEmpty public String generateIdentifier() {
return generateIdentifier(true);
}
/** {@inheritDoc} */
- public String generateIdentifier(final boolean xmlSafe) {
+ @Nonnull @NotEmpty public String generateIdentifier(final boolean xmlSafe) {
if (xmlSafe) {
return "_" + UUID.randomUUID().toString();
} else {
diff --git a/src/main/java/net/shibboleth/utilities/java/support/xml/AttributeSupport.java b/src/main/java/net/shibboleth/utilities/java/support/xml/AttributeSupport.java
index 62cbd92..9375a9c 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/xml/AttributeSupport.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/xml/AttributeSupport.java
@@ -231,7 +231,7 @@ public final class AttributeSupport {
* @return the attribute or null if the given element or attribute was null or the given attribute did not contain
* an attribute with the given name
*/
- @Nonnull public static Attr getAttribute(@Nullable final Element element, @Nullable final QName attributeName) {
+ @Nullable public static Attr getAttribute(@Nullable final Element element, @Nullable final QName attributeName) {
if (element == null || attributeName == null) {
return null;
}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/xml/NamespaceSupport.java b/src/main/java/net/shibboleth/utilities/java/support/xml/NamespaceSupport.java
index 77e7182..27eba9d 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/xml/NamespaceSupport.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/xml/NamespaceSupport.java
@@ -87,13 +87,17 @@ public final class NamespaceSupport {
* @param startingElement the starting element
* @param stoppingElement the ancestor of the starting element that serves as the upper-bound, inclusive, for the
* search
- * @param prefix the prefix to look up. If null then the default namespace is returned.
+ * @param prefix the prefix to look up. If null then the default namespace is sought and returned.
*
- * @return the namespace URI for the given prefer or null
+ * @return the namespace URI for the given prefix or null
*/
- @Nullable public static String lookupNamespaceURI(@Nonnull final Element startingElement,
- @Nullable final Element stoppingElement, @Nonnull final String prefix) {
- Constraint.isNotNull(startingElement, "Starting element may not be null");
+// Checkstyle: CyclomaticComplexity OFF
+ @Nullable public static String lookupNamespaceURI(@Nullable final Element startingElement,
+ @Nullable final Element stoppingElement, @Nullable final String prefix) {
+
+ if (startingElement == null) {
+ return null;
+ }
// This code is a modified version of the lookup code within Xerces
if (startingElement.hasAttributes()) {
@@ -127,7 +131,8 @@ public final class NamespaceSupport {
return null;
}
-
+// Checkstyle: CyclomaticComplexity ON
+
/**
* Looks up the namespace prefix associated with the given URI starting at the given element. This method differs
* from {@link Node#lookupPrefix(java.lang.String)} in that only those namespaces declared by an xmlns attribute
@@ -139,14 +144,14 @@ public final class NamespaceSupport {
* (if, for instance the prefix is associated with different namespaces at different points of the hierarchy.
*
* @param startingElement the starting element
- * @param stopingElement the ancestor of the starting element that serves as the upper-bound, inclusive, for the
+ * @param stoppingElement the ancestor of the starting element that serves as the upper-bound, inclusive, for the
* search
* @param namespaceURI the uri to look up
*
* @return the prefix for the given namespace URI or null if non exists or the the URI is for the default namespace.
*/
@Nullable public static String lookupPrefix(@Nonnull final Element startingElement,
- @Nullable final Element stopingElement, @Nullable final String namespaceURI) {
+ @Nullable final Element stoppingElement, @Nullable final String namespaceURI) {
Constraint.isNotNull(startingElement, "Starting element may not be null");
if (null == namespaceURI) {
@@ -178,10 +183,10 @@ public final class NamespaceSupport {
}
}
- if (startingElement != stopingElement) {
+ if (startingElement != stoppingElement) {
final Element ancestor = ElementSupport.getElementAncestor(startingElement);
if (ancestor != null) {
- return lookupPrefix(ancestor, stopingElement, namespaceURI);
+ return lookupPrefix(ancestor, stoppingElement, namespaceURI);
}
}
diff --git a/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java b/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java
index d946c37..0c749ec 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java
@@ -202,7 +202,7 @@ public class SchemaBuilder {
*
* @param schemaSources schema sources
*/
- @Nonnull public void setSchemas(@Nonnull @NullableElements final Collection<Source> schemaSources) {
+ public void setSchemas(@Nonnull @NullableElements final Collection<Source> schemaSources) {
Constraint.isNotNull(schemaSources, "Schema source file paths cannot be null");
resetSchemas();
@@ -222,7 +222,7 @@ public class SchemaBuilder {
*
* @param schemaResources schema resources
*/
- @Nonnull public void setSchemaResources(@Nonnull @NullableElements final Collection<Resource> schemaResources) {
+ public void setSchemaResources(@Nonnull @NullableElements final Collection<Resource> schemaResources) {
Constraint.isNotNull(schemaResources, "Schema resources cannot be null");
resetSchemas();
diff --git a/src/main/java/net/shibboleth/utilities/java/support/xml/SimpleNamespaceContext.java b/src/main/java/net/shibboleth/utilities/java/support/xml/SimpleNamespaceContext.java
index 5b5d58f..be19062 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/xml/SimpleNamespaceContext.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/xml/SimpleNamespaceContext.java
@@ -79,7 +79,7 @@ public class SimpleNamespaceContext implements NamespaceContext {
}
/** {@inheritDoc} */
- @Nullable public String getNamespaceURI(@Nonnull final String prefix) {
+ @Nullable public String getNamespaceURI(final String prefix) {
if (prefix == null) {
throw new IllegalArgumentException("Prefix can not be null");
}
@@ -93,7 +93,7 @@ public class SimpleNamespaceContext implements NamespaceContext {
}
/** {@inheritDoc} */
- @Nullable public String getPrefix(@Nonnull final String namespaceURI) {
+ @Nullable public String getPrefix(final String namespaceURI) {
if (namespaceURI == null) {
throw new IllegalArgumentException("Namespace URI can not be null");
}
diff --git a/src/test/java/net/shibboleth/utilities/java/support/component/AbstractIdentifiedInitializableComponentTest.java b/src/test/java/net/shibboleth/utilities/java/support/component/AbstractIdentifiedInitializableComponentTest.java
index 9414383..844f2b9 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/component/AbstractIdentifiedInitializableComponentTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/component/AbstractIdentifiedInitializableComponentTest.java
@@ -31,7 +31,7 @@ public class AbstractIdentifiedInitializableComponentTest {
Assert.assertNull(component.getId());
try {
- component.setId(null);
+ component.setId(nullValue());
Assert.fail();
} catch (ConstraintViolationException e) {
// expected this
@@ -81,7 +81,12 @@ public class AbstractIdentifiedInitializableComponentTest {
component.initialize();
}
+ private String nullValue() {
+ return null;
+ }
+
/** Mock component. */
private class MockComponent extends AbstractIdentifiedInitializableComponent {
}
+
}
diff --git a/src/test/java/net/shibboleth/utilities/java/support/component/ComponentSupportTest.java b/src/test/java/net/shibboleth/utilities/java/support/component/ComponentSupportTest.java
index f40ab42..ef1add3 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/component/ComponentSupportTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/component/ComponentSupportTest.java
@@ -67,7 +67,7 @@ public class ComponentSupportTest {
}
try {
- ComponentSupport.ifDestroyedThrowDestroyedComponentException(null);
+ ComponentSupport.ifDestroyedThrowDestroyedComponentException(nullValue());
Assert.fail();
} catch (ConstraintViolationException e) {
// expected this
@@ -92,7 +92,7 @@ public class ComponentSupportTest {
}
try {
- ComponentSupport.ifNotInitializedThrowUninitializedComponentException(null);
+ ComponentSupport.ifNotInitializedThrowUninitializedComponentException(nullValue());
Assert.fail();
} catch (ConstraintViolationException e) {
// expected this
@@ -117,12 +117,16 @@ public class ComponentSupportTest {
}
try {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(null);
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(nullValue());
Assert.fail();
} catch (ConstraintViolationException e) {
// expected this
}
}
+
+ private <T> T nullValue() {
+ return null;
+ }
private class MockDestructableComponent implements DestructableComponent {
diff --git a/src/test/java/net/shibboleth/utilities/java/support/logic/TransformAndCheckFunctionTest.java b/src/test/java/net/shibboleth/utilities/java/support/logic/TransformAndCheckFunctionTest.java
index 2bde74c..c643332 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/logic/TransformAndCheckFunctionTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/logic/TransformAndCheckFunctionTest.java
@@ -37,7 +37,7 @@ public class TransformAndCheckFunctionTest {
Function<String, Optional<? extends String>> f = null;
boolean thrown = false;
try {
- f = new TransformAndCheckFunction<>(null, new MyPredicate(), true);
+ f = new TransformAndCheckFunction<>(nullValue(), new MyPredicate(), true);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -45,7 +45,7 @@ public class TransformAndCheckFunctionTest {
thrown = false;
try {
- f = new TransformAndCheckFunction<>(TrimOrNullStringFunction.INSTANCE, null, true);
+ f = new TransformAndCheckFunction<>(TrimOrNullStringFunction.INSTANCE, nullValue(), true);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -71,7 +71,11 @@ public class TransformAndCheckFunctionTest {
org.testng.Assert.assertTrue(thrown, "mismatch should throw");
}
- public class MyPredicate implements Predicate<String> {
+ private <T> T nullValue() {
+ return null;
+ }
+
+ private class MyPredicate implements Predicate<String> {
/** {@inheritDoc} */
public boolean apply(String input) {
for (String s : excludes) {
@@ -81,6 +85,5 @@ public class TransformAndCheckFunctionTest {
}
return false;
}
-
}
}
diff --git a/src/test/java/net/shibboleth/utilities/java/support/primitive/StringSupportTest.java b/src/test/java/net/shibboleth/utilities/java/support/primitive/StringSupportTest.java
index fbc3c3a..59a1e6f 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/primitive/StringSupportTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/primitive/StringSupportTest.java
@@ -24,6 +24,9 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.List;
+import javax.annotation.Nonnull;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
import org.springframework.core.io.ClassPathResource;
@@ -36,15 +39,15 @@ import org.testng.annotations.Test;
*/
public class StringSupportTest {
- private static final String TRIM_TEST1 = " AARDVARK incorporated";
+ @Nonnull @NotEmpty private static final String TRIM_TEST1 = " AARDVARK incorporated";
- private static final String EMPTY_TRIM_TEST2 = " \t ";
+ @Nonnull @NotEmpty private static final String EMPTY_TRIM_TEST2 = " \t ";
- private static final String SEPARATOR = "+";
+ @Nonnull @NotEmpty private static final String SEPARATOR = "+";
- private static final String TEST_LIST = "1+x2+y3+z4+5+6+";
+ @Nonnull @NotEmpty private static final String TEST_LIST = "1+x2+y3+z4+5+6+";
- private static final List<String> TEST_LIST_AS_LIST = Arrays.asList("1", "x2", "y3", "z4", "5", "6", "");
+ @Nonnull private static final List<String> TEST_LIST_AS_LIST = Arrays.asList("1", "x2", "y3", "z4", "5", "6", "");
@Test public void testInputStreamToString() throws IOException {
String str = null;
@@ -64,7 +67,7 @@ public class StringSupportTest {
"toList<String> fails");
boolean thrown = false;
try {
- StringSupport.listToStringValue(TEST_LIST_AS_LIST, null);
+ StringSupport.listToStringValue(TEST_LIST_AS_LIST, nullValue());
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -72,7 +75,7 @@ public class StringSupportTest {
thrown = false;
try {
- StringSupport.listToStringValue(null, SEPARATOR);
+ StringSupport.listToStringValue(nullValue(), SEPARATOR);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -86,7 +89,7 @@ public class StringSupportTest {
boolean thrown = false;
try {
- StringSupport.stringToList(null, SEPARATOR);
+ StringSupport.stringToList(nullValue(), SEPARATOR);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -94,7 +97,7 @@ public class StringSupportTest {
thrown = false;
try {
- StringSupport.stringToList(TEST_LIST, null);
+ StringSupport.stringToList(TEST_LIST, nullValue());
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -146,4 +149,8 @@ public class StringSupportTest {
Assert.assertEquals(output.size(), 0);
}
-}
+ private <T> T nullValue() {
+ return null;
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/net/shibboleth/utilities/java/support/resource/TestResourceConverter.java b/src/test/java/net/shibboleth/utilities/java/support/resource/TestResourceConverter.java
index e0dee42..de08cf7 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/resource/TestResourceConverter.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/resource/TestResourceConverter.java
@@ -63,7 +63,7 @@ public final class TestResourceConverter implements net.shibboleth.utilities.jav
}
/** {@inheritDoc} */
- @Override public InputStream getInputStream() throws IOException {
+ @Override @Nonnull public InputStream getInputStream() throws IOException {
return springResource.getInputStream();
}
diff --git a/src/test/java/net/shibboleth/utilities/java/support/scripting/EvaluableScriptTest.java b/src/test/java/net/shibboleth/utilities/java/support/scripting/EvaluableScriptTest.java
index b379ab6..50dcd21 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/scripting/EvaluableScriptTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/scripting/EvaluableScriptTest.java
@@ -23,8 +23,10 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import javax.annotation.Nonnull;
import javax.script.ScriptException;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
import org.testng.Assert;
@@ -35,10 +37,10 @@ import org.testng.annotations.Test;
public class EvaluableScriptTest {
- private static final String SCRIPT_LANGUAGE = "JavaScript";
+ @Nonnull @NotEmpty private static final String SCRIPT_LANGUAGE = "JavaScript";
/** A simple script to set a constant value. */
- private static final String TEST_SIMPLE_SCRIPT = "importPackage(Packages.net.shibboleth.idp.attribute);\n"
+ @Nonnull @NotEmpty private static final String TEST_SIMPLE_SCRIPT = "importPackage(Packages.net.shibboleth.idp.attribute);\n"
+ "foo = res = new Attribute(\"bar\");\n foo.addValue(\"value\");\n";
private File theFile;
@@ -68,14 +70,14 @@ public class EvaluableScriptTest {
}
try {
- new EvaluableScript(null, TEST_SIMPLE_SCRIPT);
+ new EvaluableScript(nullValue(), TEST_SIMPLE_SCRIPT);
Assert.fail();
} catch (final ConstraintViolationException e) {
// OK
}
try {
- new EvaluableScript(SCRIPT_LANGUAGE, (String) null);
+ new EvaluableScript(SCRIPT_LANGUAGE, (String) nullValue());
Assert.fail();
} catch (final ConstraintViolationException e) {
// OK
@@ -94,18 +96,23 @@ public class EvaluableScriptTest {
}
try {
- new EvaluableScript(null, theFile);
+ new EvaluableScript(nullValue(), theFile);
Assert.fail();
} catch (final ConstraintViolationException e) {
// OK
}
try {
- new EvaluableScript(SCRIPT_LANGUAGE, (File) null);
+ new EvaluableScript(SCRIPT_LANGUAGE, (File) nullValue());
Assert.fail();
} catch (final ConstraintViolationException e) {
// OK
}
}
+
+ private <T> T nullValue() {
+ return null;
+ }
+
}
diff --git a/src/test/java/net/shibboleth/utilities/java/support/security/DataSealerTest.java b/src/test/java/net/shibboleth/utilities/java/support/security/DataSealerTest.java
index 1ef5e89..12ec22d 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/security/DataSealerTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/security/DataSealerTest.java
@@ -17,10 +17,13 @@
package net.shibboleth.utilities.java.support.security;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.resource.Resource;
import net.shibboleth.utilities.java.support.resource.TestResourceConverter;
+import javax.annotation.Nonnull;
+
import org.bouncycastle.util.Arrays;
import org.springframework.core.io.ClassPathResource;
import org.testng.Assert;
@@ -36,7 +39,8 @@ public class DataSealerTest {
private Resource versionResource;
private Resource version2Resource;
- final private String THE_DATA = "THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA"
+ @Nonnull @NotEmpty final private String THE_DATA =
+ "THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA"
+ "THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA"
+ "THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA"
+ "THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA THIS IS SOME TEST DATA";
@@ -182,11 +186,15 @@ public class DataSealerTest {
}
try {
- sealer.wrap(null, 10);
+ sealer.wrap(nullValue(), 10);
Assert.fail("no data");
} catch (IllegalArgumentException e) {
// OK
}
}
+ private <T> T nullValue() {
+ return null;
+ }
+
}
\ No newline at end of file
diff --git a/src/test/java/net/shibboleth/utilities/java/support/xml/AttributeSupportTest.java b/src/test/java/net/shibboleth/utilities/java/support/xml/AttributeSupportTest.java
index 0b8206a..676229a 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/xml/AttributeSupportTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/xml/AttributeSupportTest.java
@@ -22,9 +22,11 @@ import java.util.Arrays;
import java.util.List;
import java.util.Locale;
+import javax.annotation.Nonnull;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
@@ -45,15 +47,15 @@ import org.xml.sax.SAXException;
public class AttributeSupportTest {
// Contants to test against
- private static final String TEST_NS = "http://example.org/NameSpace";
+ @Nonnull @NotEmpty private static final String TEST_NS = "http://example.org/NameSpace";
- private static final String TEST_PREFIX = "testns";
+ @Nonnull @NotEmpty private static final String TEST_PREFIX = "testns";
- private static final String TEST_ID_ATTRIBUTE = "testAttributeName";
+ @Nonnull @NotEmpty private static final String TEST_ID_ATTRIBUTE = "testAttributeName";
- private static final String TEST_ID_PREFIXEDATTRIBUTE = TEST_PREFIX + ":" + TEST_ID_ATTRIBUTE;
+ @Nonnull @NotEmpty private static final String TEST_ID_PREFIXEDATTRIBUTE = TEST_PREFIX + ":" + TEST_ID_ATTRIBUTE;
- private static final String TEST_ID_ATTRIBUTE_VALUE = "IDAttrVALUE";
+ @Nonnull @NotEmpty private static final String TEST_ID_ATTRIBUTE_VALUE = "IDAttrVALUE";
// Set up at start of all methods
private QName idAttrQName;
@@ -175,7 +177,7 @@ public class AttributeSupportTest {
// test Add now that we know that get works
boolean thrown = false;
try {
- AttributeSupport.addXMLId(createdElement, null);
+ AttributeSupport.addXMLId(createdElement, nullValue());
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -183,7 +185,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.addXMLId(null, "fr");
+ AttributeSupport.addXMLId(nullValue(), "fr");
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -203,7 +205,7 @@ public class AttributeSupportTest {
// test Add
boolean thrown = false;
try {
- AttributeSupport.addXMLBase(createdElement, null);
+ AttributeSupport.addXMLBase(createdElement, nullValue());
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -211,7 +213,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.addXMLBase(null, "foo");
+ AttributeSupport.addXMLBase(nullValue(), "foo");
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -234,7 +236,7 @@ public class AttributeSupportTest {
// test Add
boolean thrown = false;
try {
- AttributeSupport.addXMLSpace(createdElement, null);
+ AttributeSupport.addXMLSpace(createdElement, nullValue());
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -242,7 +244,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.addXMLSpace(null, XMLSpace.DEFAULT);
+ AttributeSupport.addXMLSpace(nullValue(), XMLSpace.DEFAULT);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -277,7 +279,7 @@ public class AttributeSupportTest {
// test Add
boolean thrown = false;
try {
- AttributeSupport.addXMLLang(createdElement, null);
+ AttributeSupport.addXMLLang(createdElement, nullValue());
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -285,7 +287,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.addXMLLang(null, "fr");
+ AttributeSupport.addXMLLang(nullValue(), "fr");
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -455,7 +457,7 @@ public class AttributeSupportTest {
Assert.assertNull(AttributeSupport.getAttributeValue(createdElement, qName), "Test precondition");
boolean thrown = false;
try {
- AttributeSupport.appendAttribute(null, qName, testResult);
+ AttributeSupport.appendAttribute(nullValue(), qName, testResult);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -463,7 +465,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.appendAttribute(createdElement, null, testResult);
+ AttributeSupport.appendAttribute(createdElement, nullValue(), testResult);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -471,7 +473,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.appendAttribute(createdElement, qName, null);
+ AttributeSupport.appendAttribute(createdElement, qName, nullValue());
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -496,7 +498,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.appendAttribute(null, qName, testResult, false);
+ AttributeSupport.appendAttribute(nullValue(), qName, testResult, false);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -504,7 +506,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.appendAttribute(createdElement, null, testResult, false);
+ AttributeSupport.appendAttribute(createdElement, nullValue(), testResult, false);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -512,7 +514,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.appendAttribute(createdElement, qName, (String) null, false);
+ AttributeSupport.appendAttribute(createdElement, qName, (String) nullValue(), false);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -549,7 +551,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.appendAttribute(null, qName, data, false);
+ AttributeSupport.appendAttribute(nullValue(), qName, data, false);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -557,7 +559,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.appendAttribute(createdElement, null, data, false);
+ AttributeSupport.appendAttribute(createdElement, nullValue(), data, false);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -596,7 +598,7 @@ public class AttributeSupportTest {
Assert.assertNull(AttributeSupport.getAttributeValue(createdElement, qName), "Test precondition");
thrown = false;
try {
- AttributeSupport.appendDurationAttribute(null, qName, duration);
+ AttributeSupport.appendDurationAttribute(nullValue(), qName, duration);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -604,7 +606,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.appendDurationAttribute(createdElement, null, duration);
+ AttributeSupport.appendDurationAttribute(createdElement, nullValue(), duration);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -627,7 +629,7 @@ public class AttributeSupportTest {
Assert.assertNull(AttributeSupport.getAttributeValue(createdElement, qName), "Test precondition");
thrown = false;
try {
- AttributeSupport.appendDateTimeAttribute(null, qName, time);
+ AttributeSupport.appendDateTimeAttribute(nullValue(), qName, time);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -635,7 +637,7 @@ public class AttributeSupportTest {
thrown = false;
try {
- AttributeSupport.appendDateTimeAttribute(createdElement, null, time);
+ AttributeSupport.appendDateTimeAttribute(createdElement, nullValue(), time);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -654,4 +656,8 @@ public class AttributeSupportTest {
}
+ private <T> T nullValue() {
+ return null;
+ }
+
}
\ No newline at end of file
diff --git a/src/test/java/net/shibboleth/utilities/java/support/xml/BasicParserPoolTest.java b/src/test/java/net/shibboleth/utilities/java/support/xml/BasicParserPoolTest.java
index 573f962..a4d4884 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/xml/BasicParserPoolTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/xml/BasicParserPoolTest.java
@@ -30,9 +30,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nonnull;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.validation.Schema;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.component.DestroyedComponentException;
import net.shibboleth.utilities.java.support.component.UninitializedComponentException;
@@ -58,13 +60,13 @@ import org.xml.sax.SAXParseException;
*/
public class BasicParserPoolTest {
- private static final String TEST_DIR = "/net/shibboleth/utilities/java/support/xml/";
+ @Nonnull @NotEmpty private static final String TEST_DIR = "/net/shibboleth/utilities/java/support/xml/";
- private static final String SCHEMA_FILE = TEST_DIR + "basicParserPoolTest.xsd";
+ @Nonnull @NotEmpty private static final String SCHEMA_FILE = TEST_DIR + "basicParserPoolTest.xsd";
- private static final String XML_FILE = TEST_DIR + "basicParserPoolTest.xml";
+ @Nonnull @NotEmpty private static final String XML_FILE = TEST_DIR + "basicParserPoolTest.xml";
- private static final String DTD_FILE = TEST_DIR + "dtdParserPoolTest.xml";
+ @Nonnull @NotEmpty private static final String DTD_FILE = TEST_DIR + "dtdParserPoolTest.xml";
private BasicParserPool basicParserPool;
/** Max size of the pool we're using. */
@@ -159,7 +161,7 @@ public class BasicParserPoolTest {
basicParserPool.setXincludeAware(false);
basicParserPool.setEntityResolver(null);
try {
- basicParserPool.setErrorHandler(null);
+ basicParserPool.setErrorHandler(nullValue());
Assert.fail("Null ErrorHandler should have been rejected");
} catch (ConstraintViolationException e) {
//Expected
@@ -761,8 +763,10 @@ pool.initialize();
Assert.assertEquals(maxPoolSize, basicParserPool.getPoolSize());
}
-
-
+ private <T> T nullValue() {
+ return null;
+ }
+
// Helpers
public static class MockEntityResolver implements EntityResolver {
diff --git a/src/test/java/net/shibboleth/utilities/java/support/xml/ElementSupportTest.java b/src/test/java/net/shibboleth/utilities/java/support/xml/ElementSupportTest.java
index fab0af3..70a4df9 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/xml/ElementSupportTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/xml/ElementSupportTest.java
@@ -22,9 +22,11 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nonnull;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
@@ -44,17 +46,17 @@ import org.xml.sax.SAXException;
*/
public class ElementSupportTest {
- private static final String TEST_NS = "http://example.org/NameSpace";
+ @Nonnull @NotEmpty private static final String TEST_NS = "http://example.org/NameSpace";
- private static final String OTHER_NS = "http://example.org/OtherSpace";
+ @Nonnull @NotEmpty private static final String OTHER_NS = "http://example.org/OtherSpace";
- private static final String TEST_PREFIX = "testns";
+ @Nonnull @NotEmpty private static final String TEST_PREFIX = "testns";
- private static final String TEST_ELEMENT_NAME = "Element1";
+ @Nonnull @NotEmpty private static final String TEST_ELEMENT_NAME = "Element1";
- private static final String ROOT_ELEMENT = "Container";
+ @Nonnull @NotEmpty private static final String ROOT_ELEMENT = "Container";
- private static final QName TEST_ELEMENT_QNAME = new QName(TEST_NS, TEST_ELEMENT_NAME, TEST_PREFIX);
+ @Nonnull private static final QName TEST_ELEMENT_QNAME = new QName(TEST_NS, TEST_ELEMENT_NAME, TEST_PREFIX);
private BasicParserPool parserPool;
@@ -291,7 +293,7 @@ public class ElementSupportTest {
//
boolean thrown = false;
try {
- ElementSupport.adoptElement(null, element);
+ ElementSupport.adoptElement(nullValue(), element);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -299,7 +301,7 @@ public class ElementSupportTest {
thrown = false;
try {
- ElementSupport.adoptElement(testerDocument, null);
+ ElementSupport.adoptElement(testerDocument, nullValue());
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -332,7 +334,7 @@ public class ElementSupportTest {
Element testElement = ElementSupport.constructElement(testerDocument, TEST_ELEMENT_QNAME);
boolean thrown = false;
try {
- ElementSupport.appendChildElement(null, testElement);
+ ElementSupport.appendChildElement(nullValue(), testElement);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -369,7 +371,7 @@ public class ElementSupportTest {
"appendTextContent: initially element has no text");
boolean thrown = false;
try {
- ElementSupport.appendTextContent(null, "test");
+ ElementSupport.appendTextContent(nullValue(), "test");
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -401,7 +403,7 @@ public class ElementSupportTest {
@Test public void testConstructElementBadParms() throws XMLParserException {
boolean thrown = false;
try {
- ElementSupport.constructElement(null, TEST_ELEMENT_QNAME);
+ ElementSupport.constructElement(nullValue(), TEST_ELEMENT_QNAME);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -409,7 +411,7 @@ public class ElementSupportTest {
thrown = false;
try {
- ElementSupport.constructElement(testerDocument, null);
+ ElementSupport.constructElement(testerDocument, nullValue());
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -417,7 +419,7 @@ public class ElementSupportTest {
thrown = false;
try {
- ElementSupport.constructElement(testerDocument, TEST_NS, null, TEST_PREFIX);
+ ElementSupport.constructElement(testerDocument, TEST_NS, nullValue(), TEST_PREFIX);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -425,7 +427,7 @@ public class ElementSupportTest {
thrown = false;
try {
- ElementSupport.constructElement(null, TEST_NS, TEST_ELEMENT_NAME, TEST_PREFIX);
+ ElementSupport.constructElement(nullValue(), TEST_NS, TEST_ELEMENT_NAME, TEST_PREFIX);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -442,7 +444,7 @@ public class ElementSupportTest {
ElementSupport.constructElement(testerDocument, new QName(TEST_NS, ROOT_ELEMENT, TEST_PREFIX));
boolean thrown = false;
try {
- ElementSupport.setDocumentElement(myDocument, null);
+ ElementSupport.setDocumentElement(myDocument, nullValue());
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -450,7 +452,7 @@ public class ElementSupportTest {
thrown = false;
try {
- ElementSupport.setDocumentElement(null, myRoot);
+ ElementSupport.setDocumentElement(nullValue(), myRoot);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -479,4 +481,9 @@ public class ElementSupportTest {
parserPool.returnBuilder(builder);
}
}
+
+ private <T> T nullValue() {
+ return null;
+ }
+
}
\ No newline at end of file
diff --git a/src/test/java/net/shibboleth/utilities/java/support/xml/QNameSupportTest.java b/src/test/java/net/shibboleth/utilities/java/support/xml/QNameSupportTest.java
index 5fc14dd..dbf7ba7 100644
--- a/src/test/java/net/shibboleth/utilities/java/support/xml/QNameSupportTest.java
+++ b/src/test/java/net/shibboleth/utilities/java/support/xml/QNameSupportTest.java
@@ -19,9 +19,11 @@ package net.shibboleth.utilities.java.support.xml;
import java.io.IOException;
+import javax.annotation.Nonnull;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
@@ -39,21 +41,21 @@ import org.xml.sax.SAXException;
*/
public class QNameSupportTest {
- private static final String NAME_1 = "name1";
+ @Nonnull @NotEmpty private static final String NAME_1 = "name1";
- private static final String NAME_2 = "name2";
+ @Nonnull @NotEmpty private static final String NAME_2 = "name2";
- private static final String NAME_3 = "name3";
+ @Nonnull @NotEmpty private static final String NAME_3 = "name3";
- private static final String NAMESPACE_1 = "http://example.org/NameSpace1";
+ @Nonnull @NotEmpty private static final String NAMESPACE_1 = "http://example.org/NameSpace1";
- private static final String NAMESPACE_2 = "http://example.org/NameSpace2";
+ @Nonnull @NotEmpty private static final String NAMESPACE_2 = "http://example.org/NameSpace2";
- private static final String DEFAULT_NAMESPACE = "http://example.org/DefaultSpace";
+ @Nonnull @NotEmpty private static final String DEFAULT_NAMESPACE = "http://example.org/DefaultSpace";
- private static final String PREFIX_1 = "myns1";
+ @Nonnull @NotEmpty private static final String PREFIX_1 = "myns1";
- private static final String PREFIX_2 = "myns2";
+ @Nonnull @NotEmpty private static final String PREFIX_2 = "myns2";
private ParserPool parserPool;
@@ -123,7 +125,7 @@ public class QNameSupportTest {
thrown = false;
try {
- QNameSupport.constructQName(child, null);
+ QNameSupport.constructQName(child, nullValue());
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -131,7 +133,7 @@ public class QNameSupportTest {
thrown = false;
try {
- QNameSupport.constructQName(null, PREFIX_2 + ":" + NAME_3);
+ QNameSupport.constructQName(nullValue(), PREFIX_2 + ":" + NAME_3);
} catch (ConstraintViolationException e) {
thrown = true;
}
@@ -158,4 +160,8 @@ public class QNameSupportTest {
Assert.assertEquals(QNameSupport.qnameToContentString(new QName(NAME_2)), NAME_2);
}
-}
+ private <T> T nullValue() {
+ return null;
+ }
+
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list