Skip to content

Commit

Permalink
Merge pull request #472 from offa/nullability_annotations
Browse files Browse the repository at this point in the history
Add missing nullability annotations
  • Loading branch information
jglick authored Jan 24, 2023
2 parents 71755e3 + dd8b989 commit e8ba173
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.scriptsecurity.sandbox.groovy;

import edu.umd.cs.findbugs.annotations.NonNull;
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;

import java.lang.reflect.Constructor;
Expand All @@ -23,31 +24,31 @@ private boolean permits(Class<?> declaringClass) {
return declaringClass.getClassLoader() == scriptLoader;
}

@Override public boolean permitsMethod(Method method, Object receiver, Object[] args) {
@Override public boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
return permits(method.getDeclaringClass()) && !isIllegalSyntheticMethod(method);
}

@Override public boolean permitsConstructor(Constructor<?> constructor, Object[] args) {
@Override public boolean permitsConstructor(@NonNull Constructor<?> constructor, @NonNull Object[] args) {
return permits(constructor.getDeclaringClass()) && !isIllegalSyntheticConstructor(constructor);
}

@Override public boolean permitsStaticMethod(Method method, Object[] args) {
@Override public boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
return permits(method.getDeclaringClass()) && !isIllegalSyntheticMethod(method);
}

@Override public boolean permitsFieldGet(Field field, Object receiver) {
@Override public boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
return permits(field.getDeclaringClass()) && !isIllegalSyntheticField(field);
}

@Override public boolean permitsFieldSet(Field field, Object receiver, Object value) {
@Override public boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
return permits(field.getDeclaringClass()) && !isIllegalSyntheticField(field);
}

@Override public boolean permitsStaticFieldGet(Field field) {
@Override public boolean permitsStaticFieldGet(@NonNull Field field) {
return permits(field.getDeclaringClass()) && !isIllegalSyntheticField(field);
}

@Override public boolean permitsStaticFieldSet(Field field, Object value) {
@Override public boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
return permits(field.getDeclaringClass()) && !isIllegalSyntheticField(field);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ private final class CleanClassCollector extends ClassCollector {

@Extension public static final class DescriptorImpl extends Descriptor<SecureGroovyScript> {

@NonNull
@Override public String getDisplayName() {
return ""; // not intended to be displayed on its own
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import edu.umd.cs.findbugs.annotations.NonNull;
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;

/**
Expand All @@ -36,31 +38,31 @@
*/
public abstract class AbstractWhitelist extends Whitelist {

@Override public boolean permitsMethod(Method method, Object receiver, Object[] args) {
@Override public boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
return false;
}

@Override public boolean permitsConstructor(Constructor<?> constructor, Object[] args) {
@Override public boolean permitsConstructor(@NonNull Constructor<?> constructor, @NonNull Object[] args) {
return false;
}

@Override public boolean permitsStaticMethod(Method method, Object[] args) {
@Override public boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
return false;
}

@Override public boolean permitsFieldSet(Field field, Object receiver, Object value) {
@Override public boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
return false;
}

@Override public boolean permitsFieldGet(Field field, Object receiver) {
@Override public boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
return false;
}

@Override public boolean permitsStaticFieldSet(Field field, Object value) {
@Override public boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
return false;
}

@Override public boolean permitsStaticFieldGet(Field field) {
@Override public boolean permitsStaticFieldGet(@NonNull Field field) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.security.ACL;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -60,31 +61,31 @@ private static boolean authenticated() {
return !ACL.SYSTEM2.equals(Jenkins.getAuthentication2());
}

@Override public boolean permitsMethod(Method method, Object receiver, Object[] args) {
@Override public boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
return unrestricted.permitsMethod(method, receiver, args) || authenticated() && restricted.permitsMethod(method, receiver, args);
}

@Override public boolean permitsConstructor(Constructor<?> constructor, Object[] args) {
@Override public boolean permitsConstructor(@NonNull Constructor<?> constructor, @NonNull Object[] args) {
return unrestricted.permitsConstructor(constructor, args) || authenticated() && restricted.permitsConstructor(constructor, args);
}

@Override public boolean permitsStaticMethod(Method method, Object[] args) {
@Override public boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
return unrestricted.permitsStaticMethod(method, args) || authenticated() && restricted.permitsStaticMethod(method, args);
}

@Override public boolean permitsFieldGet(Field field, Object receiver) {
@Override public boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
return unrestricted.permitsFieldGet(field, receiver);
}

@Override public boolean permitsFieldSet(Field field, Object receiver, Object value) {
@Override public boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
return unrestricted.permitsFieldSet(field, receiver, value);
}

@Override public boolean permitsStaticFieldGet(Field field) {
@Override public boolean permitsStaticFieldGet(@NonNull Field field) {
return unrestricted.permitsStaticFieldGet(field);
}

@Override public boolean permitsStaticFieldSet(Field field, Object value) {
@Override public boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
return unrestricted.permitsStaticFieldSet(field, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,31 @@ private boolean allowed(@NonNull AccessibleObject o) {
return ann.restricted() == restricted;
}

@Override public boolean permitsMethod(Method method, Object receiver, Object[] args) {
@Override public boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
return allowed(method);
}

@Override public boolean permitsConstructor(Constructor<?> constructor, Object[] args) {
@Override public boolean permitsConstructor(@NonNull Constructor<?> constructor, @NonNull Object[] args) {
return allowed(constructor);
}

@Override public boolean permitsStaticMethod(Method method, Object[] args) {
@Override public boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
return allowed(method);
}

@Override public boolean permitsFieldGet(Field field, Object receiver) {
@Override public boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
return allowed(field);
}

@Override public boolean permitsFieldSet(Field field, Object receiver, Object value) {
@Override public boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
return allowed(field);
}

@Override public boolean permitsStaticFieldGet(Field field) {
@Override public boolean permitsStaticFieldGet(@NonNull Field field) {
return allowed(field);
}

@Override public boolean permitsStaticFieldSet(Field field, Object value) {
@Override public boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
return allowed(field);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import edu.umd.cs.findbugs.annotations.NonNull;
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;

/**
Expand All @@ -35,31 +37,31 @@
*/
public final class BlanketWhitelist extends Whitelist {

@Override public boolean permitsMethod(Method method, Object receiver, Object[] args) {
@Override public boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
return true;
}

@Override public boolean permitsConstructor(Constructor<?> constructor, Object[] args) {
@Override public boolean permitsConstructor(@NonNull Constructor<?> constructor, @NonNull Object[] args) {
return true;
}

@Override public boolean permitsStaticMethod(Method method, Object[] args) {
@Override public boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
return true;
}

@Override public boolean permitsFieldSet(Field field, Object receiver, Object value) {
@Override public boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
return true;
}

@Override public boolean permitsFieldGet(Field field, Object receiver) {
@Override public boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
return true;
}

@Override public boolean permitsStaticFieldSet(Field field, Object value) {
@Override public boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
return true;
}

@Override public boolean permitsStaticFieldGet(Field field) {
@Override public boolean permitsStaticFieldGet(@NonNull Field field) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final void clearCache() {
this.permittedCache = new ConcurrentHashMap<>();
}

@Override public final boolean permitsMethod(Method method, Object receiver, Object[] args) {
@Override public final boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
String key = canonicalMethodSig(method);
Boolean b = permittedCache.get(key);
if (b != null) {
Expand All @@ -104,7 +104,7 @@ final void clearCache() {
return output;
}

@Override public final boolean permitsConstructor(Constructor<?> constructor, Object[] args) {
@Override public final boolean permitsConstructor(@NonNull Constructor<?> constructor, @NonNull Object[] args) {
String key = canonicalConstructorSig(constructor);
Boolean b = permittedCache.get(key);
if (b != null) {
Expand All @@ -122,7 +122,7 @@ final void clearCache() {
return output;
}

@Override public final boolean permitsStaticMethod(Method method, Object[] args) {
@Override public final boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
String key = canonicalStaticMethodSig(method);
Boolean b = permittedCache.get(key);
if (b != null) {
Expand All @@ -140,7 +140,7 @@ final void clearCache() {
return output;
}

@Override public final boolean permitsFieldGet(Field field, Object receiver) {
@Override public final boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
String key = canonicalFieldSig(field);
Boolean b = permittedCache.get(key);
if (b != null) {
Expand All @@ -158,11 +158,11 @@ final void clearCache() {
return output;
}

@Override public final boolean permitsFieldSet(Field field, Object receiver, Object value) {
@Override public final boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
return permitsFieldGet(field, receiver);
}

@Override public final boolean permitsStaticFieldGet(Field field) {
@Override public final boolean permitsStaticFieldGet(@NonNull Field field) {
String key = canonicalStaticFieldSig(field);
Boolean b = permittedCache.get(key);
if (b != null) {
Expand All @@ -180,7 +180,7 @@ final void clearCache() {
return output;
}

@Override public final boolean permitsStaticFieldSet(Field field, Object value) {
@Override public final boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
return permitsStaticFieldGet(field);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import edu.umd.cs.findbugs.annotations.NonNull;
import net.jcip.annotations.GuardedBy;
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;
import java.util.ArrayList;
Expand Down Expand Up @@ -185,7 +186,7 @@ public ProxyWhitelist(Whitelist... delegates) {
this(Arrays.asList(delegates));
}

@Override public final boolean permitsMethod(Method method, Object receiver, Object[] args) {
@Override public final boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
lock.readLock().lock();
try {
for (Whitelist delegate : delegates) {
Expand All @@ -199,7 +200,7 @@ public ProxyWhitelist(Whitelist... delegates) {
return false;
}

@Override public final boolean permitsConstructor(Constructor<?> constructor, Object[] args) {
@Override public final boolean permitsConstructor(@NonNull Constructor<?> constructor, @NonNull Object[] args) {
lock.readLock().lock();
try {
for (Whitelist delegate : delegates) {
Expand All @@ -213,7 +214,7 @@ public ProxyWhitelist(Whitelist... delegates) {
return false;
}

@Override public final boolean permitsStaticMethod(Method method, Object[] args) {
@Override public final boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
lock.readLock().lock();
try {
for (Whitelist delegate : delegates) {
Expand All @@ -227,7 +228,7 @@ public ProxyWhitelist(Whitelist... delegates) {
return false;
}

@Override public final boolean permitsFieldGet(Field field, Object receiver) {
@Override public final boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
lock.readLock().lock();
try {
for (Whitelist delegate : delegates) {
Expand All @@ -241,7 +242,7 @@ public ProxyWhitelist(Whitelist... delegates) {
return false;
}

@Override public final boolean permitsFieldSet(Field field, Object receiver, Object value) {
@Override public final boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
lock.readLock().lock();
try {
for (Whitelist delegate : delegates) {
Expand All @@ -256,7 +257,7 @@ public ProxyWhitelist(Whitelist... delegates) {
return false;
}

@Override public final boolean permitsStaticFieldGet(Field field) {
@Override public final boolean permitsStaticFieldGet(@NonNull Field field) {
lock.readLock().lock();
try {
for (Whitelist delegate : delegates) {
Expand All @@ -270,7 +271,7 @@ public ProxyWhitelist(Whitelist... delegates) {
return false;
}

@Override public final boolean permitsStaticFieldSet(Field field, Object value) {
@Override public final boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
lock.readLock().lock();
try {
for (Whitelist delegate : delegates) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public boolean equals(Object obj) {

@Extension
public static class DescriptorImpl extends Descriptor<ClasspathEntry> {
@NonNull
@Override
public String getDisplayName() {
return "ClasspathEntry";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected XmlFile getConfigFile() {
return new XmlFile(XSTREAM2, new File(Jenkins.get().getRootDir(),getUrlName() + ".xml"));
}

@NonNull
@Override
public GlobalConfigurationCategory getCategory() {
return GlobalConfigurationCategory.get(GlobalConfigurationCategory.Security.class);
Expand Down Expand Up @@ -379,9 +380,11 @@ public Language getLanguage() {
}
}
return new Language() {
@NonNull
@Override public String getName() {
return language;
}
@NonNull
@Override public String getDisplayName() {
return "<missing language: " + language + ">";
}
Expand Down
Loading

0 comments on commit e8ba173

Please sign in to comment.