Hide utility class constructors

Update all utility classes so that they have a private constructor. This
prevents users from accidentally creating an instance, when they should
just use the static methods directly.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-29 15:15:15 -07:00
committed by Rob Winch
parent 8559447357
commit 01d90c9881
61 changed files with 213 additions and 52 deletions

View File

@@ -19,7 +19,10 @@ package org.springframework.security.access.annotation.sec2150;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.security.access.intercept.method.MockMethodInvocation;
public class MethodInvocationFactory {
public final class MethodInvocationFactory {
private MethodInvocationFactory() {
}
/**
* In order to reproduce the bug for SEC-2150, we must have a proxy object that

View File

@@ -16,7 +16,10 @@
package org.springframework.security.access.expression.method;
public class SecurityRules {
public final class SecurityRules {
private SecurityRules() {
}
public static boolean disallow() {
return false;

View File

@@ -27,8 +27,6 @@ public class FieldUtilsTests {
@Test
public void gettingAndSettingProtectedFieldIsSuccessful() throws Exception {
new FieldUtils();
Object tc = new TestClass();
assertThat(FieldUtils.getProtectedFieldValue("protectedField", tc)).isEqualTo("x");

View File

@@ -33,8 +33,6 @@ public class MethodInvocationUtilsTests {
@Test
public void createFromClassReturnsMethodWithNoArgInfoForMethodWithNoArgs() {
new MethodInvocationUtils();
MethodInvocation mi = MethodInvocationUtils.createFromClass(String.class, "length");
assertThat(mi).isNotNull();
}