Skip to content

Commit

Permalink
fix #2802 Prevent NullPointerException in FessMultipartRequestHandler…
Browse files Browse the repository at this point in the history
… by adding null check and fallback for tempDirFile
  • Loading branch information
marevol committed Jan 30, 2024
1 parent b50b0b9 commit 0686a8b
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.commons.fileupload2.jakarta.JakartaServletDiskFileUpload;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.fess.util.ComponentUtil;
import org.dbflute.helper.message.ExceptionMessageBuilder;
import org.lastaflute.core.message.UserMessages;
Expand All @@ -45,6 +46,7 @@
import org.lastaflute.web.ruts.multipart.exception.MultipartExceededException;
import org.lastaflute.web.util.LaServletContextUtil;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;

Expand All @@ -57,7 +59,6 @@ public class FessMultipartRequestHandler implements MultipartRequestHandler {
// Definition
// ==========
private static final Logger logger = LogManager.getLogger(FessMultipartRequestHandler.class);
protected static final String CONTEXT_TEMPDIR_KEY = "jakarta.searvlet.context.tempdir";
protected static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir";

// ===================================================================================
Expand Down Expand Up @@ -326,12 +327,14 @@ protected Integer getSizeThreshold() {
}

protected String getRepositoryPath() {
final File tempDirFile = (File) LaServletContextUtil.getServletContext().getAttribute(CONTEXT_TEMPDIR_KEY);
String tempDir = tempDirFile.getAbsolutePath();
if (tempDir == null || tempDir.length() == 0) {
tempDir = System.getProperty(JAVA_IO_TMPDIR_KEY);
final File tempDirFile = (File) LaServletContextUtil.getServletContext().getAttribute(ServletContext.TEMPDIR);
if (tempDirFile != null) {
final String tempDir = tempDirFile.getAbsolutePath();
if (StringUtil.isNotBlank(tempDir)) {
return tempDir;
}
}
return tempDir;
return System.getProperty(JAVA_IO_TMPDIR_KEY);
}

// ===================================================================================
Expand Down

0 comments on commit 0686a8b

Please sign in to comment.