Skip to content

Commit

Permalink
[Improve] @nonnull annotation improvemenets (#3808)
Browse files Browse the repository at this point in the history
* [Improve] @nonnull annotation improvements
  • Loading branch information
wolfboys authored Jun 28, 2024
1 parent e7b5041 commit a3c96eb
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@

package org.apache.streampark.console.base.exception;

import lombok.Getter;

/**
*
*
* <pre>
* An exception message that needs to be notified to front-end.
* </pre>
*/
@Getter
public abstract class AbstractApiException extends RuntimeException {

private final long responseCode;
Expand All @@ -42,8 +45,4 @@ protected AbstractApiException(String message, Throwable cause, long responseCod
super(message, cause);
this.responseCode = responseCode;
}

public long getResponseCode() {
return responseCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.web.servlet.ModelAndView;
import org.xml.sax.helpers.DefaultHandler;

import javax.annotation.Nonnull;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

Expand All @@ -49,7 +50,10 @@ public class UploadFileTypeInterceptor implements HandlerInterceptor {
private static final Logger logger = LoggerFactory.getLogger(UploadFileTypeInterceptor.class);

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
public boolean preHandle(
@Nonnull HttpServletRequest request,
@Nonnull HttpServletResponse response,
@Nonnull Object handler)
throws Exception {
if (request instanceof MultipartHttpServletRequest) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Expand All @@ -58,9 +62,13 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
MultipartFile multipartFile = multipartRequest.getFile(file);
ApiAlertException.throwIfNull(
multipartFile, "File to upload can't be null. Upload file failed.");
boolean isJarOrPyFile =
FileUtils.isJarFileType(multipartFile.getInputStream())
|| isPythonFileType(multipartFile.getContentType(), multipartFile.getInputStream());
boolean isJarOrPyFile = false;
if (multipartFile != null) {
isJarOrPyFile =
FileUtils.isJarFileType(multipartFile.getInputStream())
|| isPythonFileType(
multipartFile.getContentType(), multipartFile.getInputStream());
}
ApiAlertException.throwIfFalse(
isJarOrPyFile,
"Illegal file type, Only support standard jar files. Upload file failed.");
Expand Down Expand Up @@ -88,17 +96,20 @@ private boolean isPythonFileType(String contentType, InputStream input) {

@Override
public void postHandle(
HttpServletRequest request,
HttpServletResponse response,
Object handler,
@Nonnull HttpServletRequest request,
@Nonnull HttpServletResponse response,
@Nonnull Object handler,
ModelAndView modelAndView)
throws Exception {
HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
}

@Override
public void afterCompletion(
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
@Nonnull HttpServletRequest request,
@Nonnull HttpServletResponse response,
@Nonnull Object handler,
Exception ex)
throws Exception {
HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("unchecked")
public final class MybatisPager<T> {

public static <T> Page<T> getPage(RestRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

public class BashJavaUtils {

private static String localhost = "localhost";
private static final String localhost = "localhost";

public static void main(String[] args) throws IOException {
String action = args[0].toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;

@Component
public class SpringContextUtils implements ApplicationContextAware {

private static ApplicationContext applicationContext;

@Override
public synchronized void setApplicationContext(ApplicationContext applicationContext)
public synchronized void setApplicationContext(@Nonnull ApplicationContext applicationContext)
throws BeansException {
SpringContextUtils.applicationContext = applicationContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@
import com.google.common.collect.Sets;
import io.fabric8.kubernetes.client.KubernetesClientException;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Nonnull;

import java.io.File;
import java.net.URI;
import java.util.Date;
Expand Down Expand Up @@ -469,7 +470,7 @@ public void start(Application appParam, boolean auto) throws Exception {
});
}

@NotNull
@Nonnull
private ApplicationLog constructAppLog(Application application) {
ApplicationLog applicationLog = new ApplicationLog();
applicationLog.setOptionName(OperationEnum.START.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -479,18 +478,16 @@ private BuildPipeline createPipelineInstance(@Nonnull Application app) {
}
}

@NotNull
@Nonnull
private FlinkYarnApplicationBuildRequest buildFlinkYarnApplicationBuildRequest(
@NotNull Application app, String mainClass, String localWorkspace, String yarnProvidedPath) {
FlinkYarnApplicationBuildRequest yarnAppRequest =
new FlinkYarnApplicationBuildRequest(
app.getJobName(),
mainClass,
localWorkspace,
yarnProvidedPath,
app.getDevelopmentMode(),
getMergedDependencyInfo(app));
return yarnAppRequest;
@Nonnull Application app, String mainClass, String localWorkspace, String yarnProvidedPath) {
return new FlinkYarnApplicationBuildRequest(
app.getJobName(),
mainClass,
localWorkspace,
yarnProvidedPath,
app.getDevelopmentMode(),
getMergedDependencyInfo(app));
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -183,7 +182,7 @@ public void trigger(Long appId, @Nullable String savepointPath, @Nullable Boolea
handleSavepointResponseFuture(application, applicationLog, savepointFuture);
}

@NotNull
@Nonnull
private ApplicationLog getApplicationLog(Application application) {
ApplicationLog applicationLog = new ApplicationLog();
applicationLog.setOptionName(OperationEnum.SAVEPOINT.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -139,7 +138,7 @@ public class SparkAppBuildPipeServiceImpl
* @return Whether the pipeline was successfully started
*/
@Override
public boolean buildApplication(@NotNull Long appId, boolean forceBuild) {
public boolean buildApplication(@Nonnull Long appId, boolean forceBuild) {
// check the build environment
checkBuildEnv(appId, forceBuild);

Expand Down

0 comments on commit a3c96eb

Please sign in to comment.