Skip to content

Commit e8ba173

Browse files
authored
Merge pull request #472 from offa/nullability_annotations
Add missing nullability annotations
2 parents 71755e3 + dd8b989 commit e8ba173

19 files changed

+87
-53
lines changed

src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/groovy/ClassLoaderWhitelist.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jenkinsci.plugins.scriptsecurity.sandbox.groovy;
22

3+
import edu.umd.cs.findbugs.annotations.NonNull;
34
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;
45

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

26-
@Override public boolean permitsMethod(Method method, Object receiver, Object[] args) {
27+
@Override public boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
2728
return permits(method.getDeclaringClass()) && !isIllegalSyntheticMethod(method);
2829
}
2930

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

34-
@Override public boolean permitsStaticMethod(Method method, Object[] args) {
35+
@Override public boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
3536
return permits(method.getDeclaringClass()) && !isIllegalSyntheticMethod(method);
3637
}
3738

38-
@Override public boolean permitsFieldGet(Field field, Object receiver) {
39+
@Override public boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
3940
return permits(field.getDeclaringClass()) && !isIllegalSyntheticField(field);
4041
}
4142

42-
@Override public boolean permitsFieldSet(Field field, Object receiver, Object value) {
43+
@Override public boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
4344
return permits(field.getDeclaringClass()) && !isIllegalSyntheticField(field);
4445
}
4546

46-
@Override public boolean permitsStaticFieldGet(Field field) {
47+
@Override public boolean permitsStaticFieldGet(@NonNull Field field) {
4748
return permits(field.getDeclaringClass()) && !isIllegalSyntheticField(field);
4849
}
4950

50-
@Override public boolean permitsStaticFieldSet(Field field, Object value) {
51+
@Override public boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
5152
return permits(field.getDeclaringClass()) && !isIllegalSyntheticField(field);
5253
}
5354

src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/groovy/SecureGroovyScript.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ private final class CleanClassCollector extends ClassCollector {
524524

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

527+
@NonNull
527528
@Override public String getDisplayName() {
528529
return ""; // not intended to be displayed on its own
529530
}

src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/AbstractWhitelist.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.lang.reflect.Constructor;
2828
import java.lang.reflect.Field;
2929
import java.lang.reflect.Method;
30+
31+
import edu.umd.cs.findbugs.annotations.NonNull;
3032
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;
3133

3234
/**
@@ -36,31 +38,31 @@
3638
*/
3739
public abstract class AbstractWhitelist extends Whitelist {
3840

39-
@Override public boolean permitsMethod(Method method, Object receiver, Object[] args) {
41+
@Override public boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
4042
return false;
4143
}
4244

43-
@Override public boolean permitsConstructor(Constructor<?> constructor, Object[] args) {
45+
@Override public boolean permitsConstructor(@NonNull Constructor<?> constructor, @NonNull Object[] args) {
4446
return false;
4547
}
4648

47-
@Override public boolean permitsStaticMethod(Method method, Object[] args) {
49+
@Override public boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
4850
return false;
4951
}
5052

51-
@Override public boolean permitsFieldSet(Field field, Object receiver, Object value) {
53+
@Override public boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
5254
return false;
5355
}
5456

55-
@Override public boolean permitsFieldGet(Field field, Object receiver) {
57+
@Override public boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
5658
return false;
5759
}
5860

59-
@Override public boolean permitsStaticFieldSet(Field field, Object value) {
61+
@Override public boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
6062
return false;
6163
}
6264

63-
@Override public boolean permitsStaticFieldGet(Field field) {
65+
@Override public boolean permitsStaticFieldGet(@NonNull Field field) {
6466
return false;
6567
}
6668

src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/AclAwareWhitelist.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

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

27+
import edu.umd.cs.findbugs.annotations.NonNull;
2728
import hudson.security.ACL;
2829
import java.lang.reflect.Constructor;
2930
import java.lang.reflect.Field;
@@ -60,31 +61,31 @@ private static boolean authenticated() {
6061
return !ACL.SYSTEM2.equals(Jenkins.getAuthentication2());
6162
}
6263

63-
@Override public boolean permitsMethod(Method method, Object receiver, Object[] args) {
64+
@Override public boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
6465
return unrestricted.permitsMethod(method, receiver, args) || authenticated() && restricted.permitsMethod(method, receiver, args);
6566
}
6667

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

71-
@Override public boolean permitsStaticMethod(Method method, Object[] args) {
72+
@Override public boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
7273
return unrestricted.permitsStaticMethod(method, args) || authenticated() && restricted.permitsStaticMethod(method, args);
7374
}
7475

75-
@Override public boolean permitsFieldGet(Field field, Object receiver) {
76+
@Override public boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
7677
return unrestricted.permitsFieldGet(field, receiver);
7778
}
7879

79-
@Override public boolean permitsFieldSet(Field field, Object receiver, Object value) {
80+
@Override public boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
8081
return unrestricted.permitsFieldSet(field, receiver, value);
8182
}
8283

83-
@Override public boolean permitsStaticFieldGet(Field field) {
84+
@Override public boolean permitsStaticFieldGet(@NonNull Field field) {
8485
return unrestricted.permitsStaticFieldGet(field);
8586
}
8687

87-
@Override public boolean permitsStaticFieldSet(Field field, Object value) {
88+
@Override public boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
8889
return unrestricted.permitsStaticFieldSet(field, value);
8990
}
9091

src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/AnnotatedWhitelist.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,31 @@ private boolean allowed(@NonNull AccessibleObject o) {
6060
return ann.restricted() == restricted;
6161
}
6262

63-
@Override public boolean permitsMethod(Method method, Object receiver, Object[] args) {
63+
@Override public boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
6464
return allowed(method);
6565
}
6666

67-
@Override public boolean permitsConstructor(Constructor<?> constructor, Object[] args) {
67+
@Override public boolean permitsConstructor(@NonNull Constructor<?> constructor, @NonNull Object[] args) {
6868
return allowed(constructor);
6969
}
7070

71-
@Override public boolean permitsStaticMethod(Method method, Object[] args) {
71+
@Override public boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
7272
return allowed(method);
7373
}
7474

75-
@Override public boolean permitsFieldGet(Field field, Object receiver) {
75+
@Override public boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
7676
return allowed(field);
7777
}
7878

79-
@Override public boolean permitsFieldSet(Field field, Object receiver, Object value) {
79+
@Override public boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
8080
return allowed(field);
8181
}
8282

83-
@Override public boolean permitsStaticFieldGet(Field field) {
83+
@Override public boolean permitsStaticFieldGet(@NonNull Field field) {
8484
return allowed(field);
8585
}
8686

87-
@Override public boolean permitsStaticFieldSet(Field field, Object value) {
87+
@Override public boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
8888
return allowed(field);
8989
}
9090

src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/BlanketWhitelist.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.lang.reflect.Constructor;
2828
import java.lang.reflect.Field;
2929
import java.lang.reflect.Method;
30+
31+
import edu.umd.cs.findbugs.annotations.NonNull;
3032
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;
3133

3234
/**
@@ -35,31 +37,31 @@
3537
*/
3638
public final class BlanketWhitelist extends Whitelist {
3739

38-
@Override public boolean permitsMethod(Method method, Object receiver, Object[] args) {
40+
@Override public boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
3941
return true;
4042
}
4143

42-
@Override public boolean permitsConstructor(Constructor<?> constructor, Object[] args) {
44+
@Override public boolean permitsConstructor(@NonNull Constructor<?> constructor, @NonNull Object[] args) {
4345
return true;
4446
}
4547

46-
@Override public boolean permitsStaticMethod(Method method, Object[] args) {
48+
@Override public boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
4749
return true;
4850
}
4951

50-
@Override public boolean permitsFieldSet(Field field, Object receiver, Object value) {
52+
@Override public boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
5153
return true;
5254
}
5355

54-
@Override public boolean permitsFieldGet(Field field, Object receiver) {
56+
@Override public boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
5557
return true;
5658
}
5759

58-
@Override public boolean permitsStaticFieldSet(Field field, Object value) {
60+
@Override public boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
5961
return true;
6062
}
6163

62-
@Override public boolean permitsStaticFieldGet(Field field) {
64+
@Override public boolean permitsStaticFieldGet(@NonNull Field field) {
6365
return true;
6466
}
6567

src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/EnumeratingWhitelist.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ final void clearCache() {
8686
this.permittedCache = new ConcurrentHashMap<>();
8787
}
8888

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

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

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

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

161-
@Override public final boolean permitsFieldSet(Field field, Object receiver, Object value) {
161+
@Override public final boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
162162
return permitsFieldGet(field, receiver);
163163
}
164164

165-
@Override public final boolean permitsStaticFieldGet(Field field) {
165+
@Override public final boolean permitsStaticFieldGet(@NonNull Field field) {
166166
String key = canonicalStaticFieldSig(field);
167167
Boolean b = permittedCache.get(key);
168168
if (b != null) {
@@ -180,7 +180,7 @@ final void clearCache() {
180180
return output;
181181
}
182182

183-
@Override public final boolean permitsStaticFieldSet(Field field, Object value) {
183+
@Override public final boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
184184
return permitsStaticFieldGet(field);
185185
}
186186

src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/ProxyWhitelist.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.lang.reflect.Field;
2929
import java.lang.reflect.Method;
3030

31+
import edu.umd.cs.findbugs.annotations.NonNull;
3132
import net.jcip.annotations.GuardedBy;
3233
import org.jenkinsci.plugins.scriptsecurity.sandbox.Whitelist;
3334
import java.util.ArrayList;
@@ -185,7 +186,7 @@ public ProxyWhitelist(Whitelist... delegates) {
185186
this(Arrays.asList(delegates));
186187
}
187188

188-
@Override public final boolean permitsMethod(Method method, Object receiver, Object[] args) {
189+
@Override public final boolean permitsMethod(@NonNull Method method, @NonNull Object receiver, @NonNull Object[] args) {
189190
lock.readLock().lock();
190191
try {
191192
for (Whitelist delegate : delegates) {
@@ -199,7 +200,7 @@ public ProxyWhitelist(Whitelist... delegates) {
199200
return false;
200201
}
201202

202-
@Override public final boolean permitsConstructor(Constructor<?> constructor, Object[] args) {
203+
@Override public final boolean permitsConstructor(@NonNull Constructor<?> constructor, @NonNull Object[] args) {
203204
lock.readLock().lock();
204205
try {
205206
for (Whitelist delegate : delegates) {
@@ -213,7 +214,7 @@ public ProxyWhitelist(Whitelist... delegates) {
213214
return false;
214215
}
215216

216-
@Override public final boolean permitsStaticMethod(Method method, Object[] args) {
217+
@Override public final boolean permitsStaticMethod(@NonNull Method method, @NonNull Object[] args) {
217218
lock.readLock().lock();
218219
try {
219220
for (Whitelist delegate : delegates) {
@@ -227,7 +228,7 @@ public ProxyWhitelist(Whitelist... delegates) {
227228
return false;
228229
}
229230

230-
@Override public final boolean permitsFieldGet(Field field, Object receiver) {
231+
@Override public final boolean permitsFieldGet(@NonNull Field field, @NonNull Object receiver) {
231232
lock.readLock().lock();
232233
try {
233234
for (Whitelist delegate : delegates) {
@@ -241,7 +242,7 @@ public ProxyWhitelist(Whitelist... delegates) {
241242
return false;
242243
}
243244

244-
@Override public final boolean permitsFieldSet(Field field, Object receiver, Object value) {
245+
@Override public final boolean permitsFieldSet(@NonNull Field field, @NonNull Object receiver, Object value) {
245246
lock.readLock().lock();
246247
try {
247248
for (Whitelist delegate : delegates) {
@@ -256,7 +257,7 @@ public ProxyWhitelist(Whitelist... delegates) {
256257
return false;
257258
}
258259

259-
@Override public final boolean permitsStaticFieldGet(Field field) {
260+
@Override public final boolean permitsStaticFieldGet(@NonNull Field field) {
260261
lock.readLock().lock();
261262
try {
262263
for (Whitelist delegate : delegates) {
@@ -270,7 +271,7 @@ public ProxyWhitelist(Whitelist... delegates) {
270271
return false;
271272
}
272273

273-
@Override public final boolean permitsStaticFieldSet(Field field, Object value) {
274+
@Override public final boolean permitsStaticFieldSet(@NonNull Field field, Object value) {
274275
lock.readLock().lock();
275276
try {
276277
for (Whitelist delegate : delegates) {

src/main/java/org/jenkinsci/plugins/scriptsecurity/scripts/ClasspathEntry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public boolean equals(Object obj) {
197197

198198
@Extension
199199
public static class DescriptorImpl extends Descriptor<ClasspathEntry> {
200+
@NonNull
200201
@Override
201202
public String getDisplayName() {
202203
return "ClasspathEntry";

src/main/java/org/jenkinsci/plugins/scriptsecurity/scripts/ScriptApproval.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ protected XmlFile getConfigFile() {
116116
return new XmlFile(XSTREAM2, new File(Jenkins.get().getRootDir(),getUrlName() + ".xml"));
117117
}
118118

119+
@NonNull
119120
@Override
120121
public GlobalConfigurationCategory getCategory() {
121122
return GlobalConfigurationCategory.get(GlobalConfigurationCategory.Security.class);
@@ -379,9 +380,11 @@ public Language getLanguage() {
379380
}
380381
}
381382
return new Language() {
383+
@NonNull
382384
@Override public String getName() {
383385
return language;
384386
}
387+
@NonNull
385388
@Override public String getDisplayName() {
386389
return "<missing language: " + language + ">";
387390
}

0 commit comments

Comments
 (0)