Skip to content

Commit b5bb523

Browse files
Add NonNullByDefault annotations to all relevant files
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
1 parent 0dd5c4c commit b5bb523

172 files changed

Lines changed: 1459 additions & 919 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/AbstractRemoteAddonService.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ public void install(String id) {
239239
return;
240240
}
241241
for (MarketplaceAddonHandler handler : addonHandlers) {
242-
if (handler.supports(addon.getType(), addon.getContentType())) {
242+
String type = addon.getType();
243+
String contentType = addon.getContentType();
244+
if (type != null && contentType != null && handler.supports(type, contentType)) {
243245
if (!handler.isInstalled(addon.getUid())) {
244246
try {
245247
handler.install(addon);
@@ -268,7 +270,9 @@ public void uninstall(String id) {
268270
return;
269271
}
270272
for (MarketplaceAddonHandler handler : addonHandlers) {
271-
if (handler.supports(addon.getType(), addon.getContentType())) {
273+
String type = addon.getType();
274+
String contentType = addon.getContentType();
275+
if (type != null && contentType != null && handler.supports(type, contentType)) {
272276
if (handler.isInstalled(addon.getUid())) {
273277
try {
274278
handler.uninstall(addon);

bundles/org.openhab.core.addon.marketplace/src/main/java/org/openhab/core/addon/marketplace/MarketplaceConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
*/
1313
package org.openhab.core.addon.marketplace;
1414

15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
1517
/**
1618
* This class contains constants used in marketplace add-on services
1719
*
1820
* @author Jan N. Klug - Initial contribution
1921
*/
22+
@NonNullByDefault
2023
public class MarketplaceConstants {
2124
public static final String JAR_CONTENT_TYPE = "application/vnd.openhab.bundle";
2225
public static final String KAR_CONTENT_TYPE = "application/vnd.openhab.feature;type=karfile";

bundles/org.openhab.core.addon/src/main/java/org/openhab/core/addon/Addon.java

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Objects;
1919
import java.util.Set;
2020

21+
import org.eclipse.jdt.annotation.NonNullByDefault;
2122
import org.eclipse.jdt.annotation.Nullable;
2223

2324
/**
@@ -26,30 +27,31 @@
2627
* @author Kai Kreuzer - Initial contribution
2728
* @author Yannick Schaus - Add fields
2829
*/
30+
@NonNullByDefault
2931
public class Addon {
3032
public static final Set<String> CODE_MATURITY_LEVELS = Set.of("alpha", "beta", "mature", "stable");
3133
public static final String ADDON_SEPARATOR = "-";
3234

3335
private final String uid;
3436

35-
private final String id;
36-
private final String label;
37+
private final @Nullable String id;
38+
private final @Nullable String label;
3739
private final String version;
3840
private final @Nullable String maturity;
3941
private final boolean compatible;
40-
private final String contentType;
42+
private final @Nullable String contentType;
4143
private final @Nullable String link;
4244
private final String author;
4345
private final boolean verifiedAuthor;
4446
private boolean installed;
45-
private final String type;
47+
private final @Nullable String type;
4648
private final @Nullable String description;
4749
private final @Nullable String detailedDescription;
4850
private final String configDescriptionURI;
4951
private final String keywords;
5052
private final List<String> countries;
5153
private final @Nullable String license;
52-
private final String connection;
54+
private final @Nullable String connection;
5355
private final @Nullable String backgroundColor;
5456
private final @Nullable String imageLink;
5557
private final Map<String, Object> properties;
@@ -84,12 +86,12 @@ public class Addon {
8486
* @param loggerPackages a {@link List} containing the package names belonging to this add-on
8587
* @throws IllegalArgumentException when a mandatory parameter is invalid
8688
*/
87-
private Addon(String uid, String type, String id, String label, String version, @Nullable String maturity,
88-
boolean compatible, String contentType, @Nullable String link, String author, boolean verifiedAuthor,
89-
boolean installed, @Nullable String description, @Nullable String detailedDescription,
90-
String configDescriptionURI, String keywords, List<String> countries, @Nullable String license,
91-
String connection, @Nullable String backgroundColor, @Nullable String imageLink,
92-
@Nullable Map<String, Object> properties, List<String> loggerPackages) {
89+
private Addon(String uid, @Nullable String type, @Nullable String id, @Nullable String label, String version,
90+
@Nullable String maturity, boolean compatible, @Nullable String contentType, @Nullable String link,
91+
String author, boolean verifiedAuthor, boolean installed, @Nullable String description,
92+
@Nullable String detailedDescription, String configDescriptionURI, String keywords, List<String> countries,
93+
@Nullable String license, @Nullable String connection, @Nullable String backgroundColor,
94+
@Nullable String imageLink, @Nullable Map<String, Object> properties, List<String> loggerPackages) {
9395
if (uid.isBlank()) {
9496
throw new IllegalArgumentException("uid must not be empty");
9597
}
@@ -129,7 +131,7 @@ private Addon(String uid, String type, String id, String label, String version,
129131
/**
130132
* The type of the addon (same as id of {@link AddonType})
131133
*/
132-
public String getType() {
134+
public @Nullable String getType() {
133135
return type;
134136
}
135137

@@ -143,14 +145,14 @@ public String getUid() {
143145
/**
144146
* The id of the add-on (e.g. "influxdb")
145147
*/
146-
public String getId() {
148+
public @Nullable String getId() {
147149
return id;
148150
}
149151

150152
/**
151153
* The label of the add-on
152154
*/
153-
public String getLabel() {
155+
public @Nullable String getLabel() {
154156
return label;
155157
}
156158

@@ -199,7 +201,7 @@ public boolean getCompatible() {
199201
/**
200202
* The content type of the add-on
201203
*/
202-
public String getContentType() {
204+
public @Nullable String getContentType() {
203205
return contentType;
204206
}
205207

@@ -248,7 +250,7 @@ public List<String> getCountries() {
248250
/**
249251
* A string describing the type of connection (local, cloud, cloudDiscovery) this add-on uses, if applicable.
250252
*/
251-
public String getConnection() {
253+
public @Nullable String getConnection() {
252254
return connection;
253255
}
254256

@@ -333,24 +335,24 @@ public static Builder create(Addon addon) {
333335

334336
public static class Builder {
335337
private final String uid;
336-
private String id;
337-
private String label;
338+
private @Nullable String id;
339+
private @Nullable String label;
338340
private String version = "";
339341
private @Nullable String maturity;
340342
private boolean compatible = true;
341-
private String contentType;
343+
private @Nullable String contentType;
342344
private @Nullable String link;
343345
private String author = "";
344346
private boolean verifiedAuthor = false;
345347
private boolean installed = false;
346-
private String type;
348+
private @Nullable String type;
347349
private @Nullable String description;
348350
private @Nullable String detailedDescription;
349351
private String configDescriptionURI = "";
350352
private String keywords = "";
351353
private List<String> countries = List.of();
352354
private @Nullable String license;
353-
private String connection = "";
355+
private @Nullable String connection = "";
354356
private @Nullable String backgroundColor;
355357
private @Nullable String imageLink;
356358
private Map<String, Object> properties = new HashMap<>();
@@ -360,17 +362,17 @@ private Builder(String uid) {
360362
this.uid = uid;
361363
}
362364

363-
public Builder withType(String type) {
365+
public Builder withType(@Nullable String type) {
364366
this.type = type;
365367
return this;
366368
}
367369

368-
public Builder withId(String id) {
370+
public Builder withId(@Nullable String id) {
369371
this.id = id;
370372
return this;
371373
}
372374

373-
public Builder withLabel(String label) {
375+
public Builder withLabel(@Nullable String label) {
374376
this.label = label;
375377
return this;
376378
}
@@ -395,7 +397,7 @@ public Builder withContentType(String contentType) {
395397
return this;
396398
}
397399

398-
public Builder withLink(String link) {
400+
public Builder withLink(@Nullable String link) {
399401
this.link = link;
400402
return this;
401403
}
@@ -416,12 +418,12 @@ public Builder withInstalled(boolean installed) {
416418
return this;
417419
}
418420

419-
public Builder withDescription(String description) {
421+
public Builder withDescription(@Nullable String description) {
420422
this.description = description;
421423
return this;
422424
}
423425

424-
public Builder withDetailedDescription(String detailedDescription) {
426+
public Builder withDetailedDescription(@Nullable String detailedDescription) {
425427
this.detailedDescription = detailedDescription;
426428
return this;
427429
}
@@ -446,12 +448,12 @@ public Builder withLicense(@Nullable String license) {
446448
return this;
447449
}
448450

449-
public Builder withConnection(String connection) {
451+
public Builder withConnection(@Nullable String connection) {
450452
this.connection = connection;
451453
return this;
452454
}
453455

454-
public Builder withBackgroundColor(String backgroundColor) {
456+
public Builder withBackgroundColor(@Nullable String backgroundColor) {
455457
this.backgroundColor = backgroundColor;
456458
return this;
457459
}

bundles/org.openhab.core.auth.jaas/src/main/java/org/openhab/core/auth/jaas/internal/ManagedUserLoginConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@
1818
import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
1919
import javax.security.auth.login.Configuration;
2020

21+
import org.eclipse.jdt.annotation.NonNullByDefault;
22+
import org.eclipse.jdt.annotation.Nullable;
23+
2124
/**
2225
* Describes a JAAS configuration with the {@link ManagedUserLoginModule} as a sufficient login module.
2326
*
2427
* @author Yannick Schaus - initial contribution
2528
*/
29+
@NonNullByDefault
2630
public class ManagedUserLoginConfiguration extends Configuration {
2731

2832
@Override
29-
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
33+
public AppConfigurationEntry @Nullable [] getAppConfigurationEntry(@Nullable String name) {
3034
return new AppConfigurationEntry[] { new AppConfigurationEntry(ManagedUserLoginModule.class.getCanonicalName(),
3135
LoginModuleControlFlag.SUFFICIENT, new HashMap<>()) };
3236
}

bundles/org.openhab.core.auth.jaas/src/main/java/org/openhab/core/auth/jaas/internal/ManagedUserLoginModule.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import javax.security.auth.login.LoginException;
2020
import javax.security.auth.spi.LoginModule;
2121

22+
import org.eclipse.jdt.annotation.NonNullByDefault;
23+
import org.eclipse.jdt.annotation.Nullable;
2224
import org.openhab.core.auth.AuthenticationException;
2325
import org.openhab.core.auth.Credentials;
2426
import org.openhab.core.auth.UserRegistry;
@@ -33,15 +35,17 @@
3335
*
3436
* @author Yannick Schaus - initial contribution
3537
*/
38+
@NonNullByDefault
3639
public class ManagedUserLoginModule implements LoginModule {
3740

3841
private final Logger logger = LoggerFactory.getLogger(ManagedUserLoginModule.class);
3942

40-
private UserRegistry userRegistry;
43+
private @Nullable UserRegistry userRegistry;
4144

42-
private Subject subject;
45+
private @Nullable Subject subject;
4346

4447
@Override
48+
@NonNullByDefault({})
4549
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState,
4650
Map<String, ?> options) {
4751
this.subject = subject;

bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/Keyword.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
*/
1313
package org.openhab.core.auth.oauth2client.internal;
1414

15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
1517
/**
1618
* Just a place to store all the important, reused keywords.
1719
*
1820
* @author Gary Tse - Initial contribution
1921
*/
22+
@NonNullByDefault
2023
public interface Keyword {
2124

2225
String CLIENT_ID = "client_id";

bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthConnector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ public AccessTokenResponse grantTypePassword(String tokenUrl, String username, S
214214
* @throws OAuthResponseException Error codes given by authorization provider, as in RFC 6749 section 5.2 Error
215215
* Response
216216
*/
217-
public AccessTokenResponse grantTypeRefreshToken(String tokenUrl, String refreshToken, @Nullable String clientId,
218-
@Nullable String clientSecret, @Nullable String scope, boolean supportsBasicAuth)
217+
public AccessTokenResponse grantTypeRefreshToken(String tokenUrl, @Nullable String refreshToken,
218+
@Nullable String clientId, @Nullable String clientSecret, @Nullable String scope, boolean supportsBasicAuth)
219219
throws OAuthResponseException, OAuthException, IOException {
220220
HttpClient httpClient = null;
221221
try {

bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthConnectorRFC8628.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ public class OAuthConnectorRFC8628 extends OAuthConnector implements AutoCloseab
8282
private final ScheduledExecutorService scheduler;
8383
private final String handle;
8484

85-
private final String accessTokenRequestUrl;
86-
private final String deviceCodeRequestUrl;
87-
private final String clientIdParameter;
88-
private final String scopeParameter;
85+
private final @Nullable String accessTokenRequestUrl;
86+
private final @Nullable String deviceCodeRequestUrl;
87+
private final @Nullable String clientIdParameter;
88+
private final @Nullable String scopeParameter;
8989

9090
private @Nullable ScheduledFuture<?> atrPollTaskSchedule;
9191
private @Nullable DeviceCodeResponseDTO dcrCached;
@@ -110,8 +110,8 @@ public class OAuthConnectorRFC8628 extends OAuthConnector implements AutoCloseab
110110
*/
111111
public OAuthConnectorRFC8628(OAuthClientService oAuthClientService, String handle,
112112
OAuthStoreHandler oAuthStoreHandler, HttpClientFactory httpClientFactory, @Nullable GsonBuilder gsonBuilder,
113-
String accessTokenRequestUrl, String deviceCodeRequestUrl, String clientId, String scope)
114-
throws OAuthException {
113+
@Nullable String accessTokenRequestUrl, @Nullable String deviceCodeRequestUrl, @Nullable String clientId,
114+
@Nullable String scope) throws OAuthException {
115115
super(httpClientFactory, null, gsonBuilder != null ? gsonBuilder : new GsonBuilder());
116116
this.oAuthClientService = oAuthClientService;
117117
this.oAuthStoreHandler = oAuthStoreHandler;

bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthStoreHandlerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private DeviceCodeResponseDTO decryptDeviceCodeResponse(DeviceCodeResponseDTO dc
252252
return dcrDecrypted;
253253
}
254254

255-
private @Nullable String encrypt(String token) throws GeneralSecurityException {
255+
private @Nullable String encrypt(@Nullable String token) throws GeneralSecurityException {
256256
if (storageCipher.isEmpty()) {
257257
return token; // do nothing if no cipher
258258
} else {

bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/PersistedParams.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package org.openhab.core.auth.oauth2client.internal;
1414

15+
import org.eclipse.jdt.annotation.NonNullByDefault;
1516
import org.eclipse.jdt.annotation.Nullable;
1617

1718
/**
@@ -22,15 +23,25 @@
2223
* @author Hilbrand Bouwkamp - Moved class to it's own file and added hashCode and equals methods
2324
* @author Gaël L'hopital - Added deserializerClassName
2425
*/
26+
@NonNullByDefault
2527
class PersistedParams {
28+
@Nullable
2629
String handle;
30+
@Nullable
2731
String tokenUrl;
32+
@Nullable
2833
String authorizationUrl;
34+
@Nullable
2935
String clientId;
36+
@Nullable
3037
String clientSecret;
38+
@Nullable
3139
String scope;
40+
@Nullable
3241
Boolean supportsBasicAuth;
42+
@Nullable
3343
String state;
44+
@Nullable
3445
String redirectUri;
3546
int tokenExpiresInSeconds = 60;
3647

@@ -58,9 +69,9 @@ public PersistedParams() {
5869
* official stated expiry time; thus prevents the caller obtaining a valid token at the time of invoke,
5970
* only to find the token immediately expired.
6071
*/
61-
public PersistedParams(String handle, String tokenUrl, String authorizationUrl, String clientId,
62-
String clientSecret, String scope, Boolean supportsBasicAuth, int tokenExpiresInSeconds,
63-
@Nullable String deserializerClassName) {
72+
public PersistedParams(@Nullable String handle, @Nullable String tokenUrl, @Nullable String authorizationUrl,
73+
@Nullable String clientId, @Nullable String clientSecret, @Nullable String scope,
74+
@Nullable Boolean supportsBasicAuth, int tokenExpiresInSeconds, @Nullable String deserializerClassName) {
6475
this.handle = handle;
6576
this.tokenUrl = tokenUrl;
6677
this.authorizationUrl = authorizationUrl;

0 commit comments

Comments
 (0)