Skip to content

Development: Migrate nullness annotations to JSpecify #9219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ dependencies {
// use newest version of guava to avoid security issues through outdated dependencies
implementation "com.google.guava:guava:33.2.1-jre"
implementation "com.sun.activation:jakarta.activation:2.0.1"
implementation "org.jspecify:jspecify:1.0.0"

// use newest version of gson to avoid security issues through outdated dependencies
implementation "com.google.code.gson:gson:2.11.0"
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/guidelines/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ In order to load the relationships of an entity on demand, we then use one of 3


// ProgrammingExerciseRepository.java
@NotNull
@NonNull
default ProgrammingExercise findByIdWithDynamicFetchElseThrow(long exerciseId, Collection<ProgrammingExerciseFetchOptions> fetchOptions) throws EntityNotFoundException {
var specification = getDynamicSpecification(fetchOptions);
return findOneByIdElseThrow(specification, exerciseId, "Programming Exercise");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

import jakarta.annotation.Nullable;
import jakarta.annotation.PreDestroy;

import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jakarta.validation.constraints.NotNull;

import org.jspecify.annotations.NonNull;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.http.CacheControl;
Expand All @@ -33,7 +32,7 @@ public PublicResourcesConfiguration(JHipsterProperties jHipsterProperties) {
}

@Override
public void addResourceHandlers(@NotNull ResourceHandlerRegistry registry) {
public void addResourceHandlers(@NonNull ResourceHandlerRegistry registry) {
// Enable static resource serving in general from "/public" from both classpath and hosts filesystem
addResourceHandlerForPath(registry);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import java.util.ArrayList;

import jakarta.validation.constraints.NotNull;

import org.jspecify.annotations.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -136,7 +135,7 @@ public RestTemplate shortTimeoutAeolusRestTemplate() {
return createShortTimeoutRestTemplate();
}

@NotNull
@NonNull
private RestTemplate initializeRestTemplateWithInterceptors(ClientHttpRequestInterceptor interceptor, RestTemplate restTemplate) {
var interceptors = restTemplate.getInterceptors();
if (interceptors.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import java.io.IOException;

import jakarta.validation.constraints.NotNull;

import org.jspecify.annotations.NonNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpHeaders;
Expand All @@ -23,7 +22,7 @@ public class AthenaAuthorizationInterceptor implements ClientHttpRequestIntercep
@Value("${server.url}")
private String artemisServerUrl;

@NotNull
@NonNull
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().set(HttpHeaders.AUTHORIZATION, secret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import java.io.IOException;

import jakarta.validation.constraints.NotNull;

import org.jspecify.annotations.NonNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpHeaders;
Expand All @@ -20,7 +19,7 @@ public class PyrisAuthorizationInterceptor implements ClientHttpRequestIntercept
@Value("${artemis.iris.secret-token}")
private String secret;

@NotNull
@NonNull
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().set(HttpHeaders.AUTHORIZATION, secret);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import java.util.Optional;
import java.util.regex.Pattern;

import jakarta.annotation.Nullable;
import jakarta.servlet.http.Cookie;
import jakarta.validation.constraints.NotNull;

import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -117,7 +117,7 @@ public WebsocketConfiguration(MappingJackson2HttpMessageConverter springMvcJacks
}

@Override
protected void configureMessageBroker(@NotNull MessageBrokerRegistry config) {
protected void configureMessageBroker(@NonNull MessageBrokerRegistry config) {
// Try to create a TCP client that will connect to the message broker (or the message brokers if multiple exists).
// If tcpClient is null, there is no valid address specified in the config. This could be due to a development setup or a mistake in the config.
TcpOperations<byte[]> tcpClient = createTcpClient();
Expand Down Expand Up @@ -180,7 +180,7 @@ public void configureClientInboundChannel(ChannelRegistration registration) {
registration.interceptors(new TopicSubscriptionInterceptor());
}

@NotNull
@NonNull
@Override
protected MappingJackson2MessageConverter createJacksonConverter() {
// NOTE: We need to adapt the default messageConverter for WebSocket messages
Expand All @@ -199,8 +199,8 @@ public HandshakeInterceptor httpSessionHandshakeInterceptor() {
return new HandshakeInterceptor() {

@Override
public boolean beforeHandshake(@NotNull ServerHttpRequest request, @NotNull ServerHttpResponse response, @NotNull WebSocketHandler wsHandler,
@NotNull Map<String, Object> attributes) {
public boolean beforeHandshake(@NonNull ServerHttpRequest request, @NonNull ServerHttpResponse response, @NonNull WebSocketHandler wsHandler,
@NonNull Map<String, Object> attributes) {
if (request instanceof ServletServerHttpRequest servletRequest) {
attributes.put(IP_ADDRESS, servletRequest.getRemoteAddress());
Cookie jwtCookie = WebUtils.getCookie(servletRequest.getServletRequest(), JWTFilter.JWT_COOKIE_NAME);
Expand All @@ -210,7 +210,7 @@ public boolean beforeHandshake(@NotNull ServerHttpRequest request, @NotNull Serv
}

@Override
public void afterHandshake(@NotNull ServerHttpRequest request, @NotNull ServerHttpResponse response, @NotNull WebSocketHandler wsHandler, Exception exception) {
public void afterHandshake(@NonNull ServerHttpRequest request, @NonNull ServerHttpResponse response, @NonNull WebSocketHandler wsHandler, Exception exception) {
if (exception != null) {
log.warn("Exception occurred in WS.afterHandshake", exception);
}
Expand All @@ -222,7 +222,7 @@ private DefaultHandshakeHandler defaultHandshakeHandler() {
return new DefaultHandshakeHandler() {

@Override
protected Principal determineUser(@NotNull ServerHttpRequest request, @NotNull WebSocketHandler wsHandler, @NotNull Map<String, Object> attributes) {
protected Principal determineUser(@NonNull ServerHttpRequest request, @NonNull WebSocketHandler wsHandler, @NonNull Map<String, Object> attributes) {
Principal principal = request.getPrincipal();
if (principal == null) {
Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
Expand All @@ -245,7 +245,7 @@ public class TopicSubscriptionInterceptor implements ChannelInterceptor {
* @return message that gets sent along further
*/
@Override
public Message<?> preSend(@NotNull Message<?> message, @NotNull MessageChannel channel) {
public Message<?> preSend(@NonNull Message<?> message, @NonNull MessageChannel channel) {
StompHeaderAccessor headerAccessor = StompHeaderAccessor.wrap(message);
Principal principal = headerAccessor.getUser();
String destination = headerAccessor.getDestination();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/tum/in/www1/artemis/domain/Authority.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.jspecify.annotations.NonNull;

import com.fasterxml.jackson.annotation.JsonInclude;

Expand Down Expand Up @@ -40,7 +40,7 @@ public class Authority implements Serializable {

public static final Authority USER_AUTHORITY = new Authority(Role.STUDENT.getAuthority());

@NotNull
@NonNull
@Size(max = 50)
@Id
@Column(length = 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import java.time.ZonedDateTime;

import jakarta.annotation.Nullable;
import jakarta.persistence.Column;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.MappedSuperclass;

import org.jspecify.annotations.Nullable;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Optional;
import java.util.Set;

import jakarta.annotation.Nullable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
Expand All @@ -16,6 +15,7 @@

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.jspecify.annotations.Nullable;

import com.fasterxml.jackson.annotation.JsonInclude;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/tum/in/www1/artemis/domain/Commit.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.tum.in.www1.artemis.domain;

import jakarta.annotation.Nullable;
import org.jspecify.annotations.Nullable;

public record Commit(@Nullable String commitHash, @Nullable String authorName, @Nullable String message, @Nullable String authorEmail, @Nullable String branch) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jakarta.annotation.Nullable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
Expand All @@ -39,6 +38,7 @@

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.jspecify.annotations.Nullable;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Optional;
import java.util.Set;

import jakarta.annotation.Nullable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -26,6 +25,7 @@
import org.hibernate.Hibernate;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.jspecify.annotations.Nullable;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Objects;
import java.util.Set;

import jakarta.annotation.Nullable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -15,11 +14,12 @@
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
Expand Down Expand Up @@ -219,7 +219,7 @@ public void setPlagiarismGrade(String plagiarismGrade) {
}

@JsonIgnore
@NotNull
@NonNull
public String getPlagiarismGradeOrDefault() {
return Objects.requireNonNullElse(plagiarismGrade, DEFAULT_PLAGIARISM_GRADE);
}
Expand All @@ -233,7 +233,7 @@ public void setNoParticipationGrade(String noParticipationGrade) {
}

@JsonIgnore
@NotNull
@NonNull
public String getNoParticipationGradeOrDefault() {
return Objects.requireNonNullElse(noParticipationGrade, DEFAULT_NO_PARTICIPATION_GRADE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import java.util.HashSet;
import java.util.Set;

import jakarta.annotation.Nullable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;

import org.hibernate.Hibernate;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -31,11 +31,11 @@ public class LtiPlatformConfiguration extends DomainObject {
/** Entity name for LTI platform configuration. */
public static final String ENTITY_NAME = "ltiPlatformConfiguration";

@NotNull
@NonNull
@Column(name = "registration_id", nullable = false)
private String registrationId;

@NotNull
@NonNull
@Column(name = "client_id", nullable = false)
private String clientId;

Expand All @@ -47,15 +47,15 @@ public class LtiPlatformConfiguration extends DomainObject {
@Column(name = "custom_name")
private String customName;

@NotNull
@NonNull
@Column(name = "authorization_uri", nullable = false)
private String authorizationUri;

@NotNull
@NonNull
@Column(name = "jwk_set_uri", nullable = false)
private String jwkSetUri;

@NotNull
@NonNull
@Column(name = "token_uri", nullable = false)
private String tokenUri;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.jspecify.annotations.NonNull;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -22,12 +22,12 @@
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Organization extends DomainObject {

@NotNull
@NonNull
@Size(max = 100)
@Column(name = "name", length = 100)
private String name;

@NotNull
@NonNull
@Size(max = 50)
@Column(name = "shortName", length = 50)
private String shortName;
Expand All @@ -41,7 +41,7 @@ public class Organization extends DomainObject {
@Column(name = "logoUrl")
private String logoUrl;

@NotNull
@NonNull
@Column(name = "emailPattern")
private String emailPattern;

Expand Down
Loading
Loading