From 06047911dcc7e18d31b7b31c3e431ad0f6db02bb Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 10 Oct 2024 07:02:21 -0400 Subject: [PATCH] Port to Java 1.4 Throwable APIs (!) --- src/changes/changes.xml | 1 + .../commons/fileupload/FileUploadBase.java | 32 +++------- .../fileupload/FileUploadException.java | 59 +++---------------- 3 files changed, 15 insertions(+), 77 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 1063413f62..e12752b5f3 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -51,6 +51,7 @@ The type attribute can be add,update,fix,remove. Remove unused exception from FileUploadBase.createItem(Map, boolean). Migrate from deprecated API in DiskFileItem.getOutputStream(). Use try-with-resources. + Port to Java 1.4 Throwable APIs (!). Bump Java from 6 to 8. Bump commons-parent from 62 to 76. diff --git a/src/main/java/org/apache/commons/fileupload/FileUploadBase.java b/src/main/java/org/apache/commons/fileupload/FileUploadBase.java index 469c411091..c9c824c25a 100644 --- a/src/main/java/org/apache/commons/fileupload/FileUploadBase.java +++ b/src/main/java/org/apache/commons/fileupload/FileUploadBase.java @@ -662,13 +662,13 @@ public InvalidContentTypeException(final String message) { * Constructs an {@code InvalidContentTypeException} with * the specified detail message and cause. * - * @param msg The detail message. + * @param message The detail message. * @param cause the original cause * * @since 1.3.1 */ - public InvalidContentTypeException(final String msg, final Throwable cause) { - super(msg, cause); + public InvalidContentTypeException(final String message, final Throwable cause) { + super(message, cause); } } @@ -682,32 +682,14 @@ public static class IOFileUploadException extends FileUploadException { */ private static final long serialVersionUID = 1749796615868477269L; - /** - * The exceptions cause; we overwrite the parent - * classes field, which is available since Java - * 1.4 only. - */ - private final IOException cause; - /** * Creates a new instance with the given cause. * - * @param pMsg The detail message. - * @param pException The exceptions cause. - */ - public IOFileUploadException(final String pMsg, final IOException pException) { - super(pMsg); - cause = pException; - } - - /** - * Returns the exceptions cause. - * - * @return The exceptions cause, if any, or null. + * @param message The detail message. + * @param cause The exceptions cause. */ - @Override - public Throwable getCause() { - return cause; + public IOFileUploadException(final String message, final IOException cause) { + super(message, cause); } } diff --git a/src/main/java/org/apache/commons/fileupload/FileUploadException.java b/src/main/java/org/apache/commons/fileupload/FileUploadException.java index f1c4a70266..4077cf4f87 100644 --- a/src/main/java/org/apache/commons/fileupload/FileUploadException.java +++ b/src/main/java/org/apache/commons/fileupload/FileUploadException.java @@ -16,9 +16,6 @@ */ package org.apache.commons.fileupload; -import java.io.PrintStream; -import java.io.PrintWriter; - /** * Exception for errors encountered while processing the request. */ @@ -30,74 +27,32 @@ public class FileUploadException extends Exception { */ private static final long serialVersionUID = 8881893724388807504L; - /** - * The exceptions cause. We overwrite the cause of - * the super class, which isn't available in Java 1.3. - */ - private final Throwable cause; - /** * Constructs a new {@code FileUploadException} without message. */ public FileUploadException() { - this(null, null); + // empty } /** * Constructs a new {@code FileUploadException} with specified detail * message. * - * @param msg the error message. + * @param message the error message. */ - public FileUploadException(final String msg) { - this(msg, null); + public FileUploadException(final String message) { + super(message); } /** * Creates a new {@code FileUploadException} with the given * detail message and cause. * - * @param msg The exceptions detail message. + * @param message The exceptions detail message. * @param cause The exceptions cause. */ - public FileUploadException(final String msg, final Throwable cause) { - super(msg); - this.cause = cause; - } - - @SuppressWarnings("sync-override") - @Override - public Throwable getCause() { - return cause; - } - - /** - * Prints this throwable and its backtrace to the specified print stream. - * - * @param stream {@code PrintStream} to use for output - */ - @Override - public void printStackTrace(final PrintStream stream) { - super.printStackTrace(stream); - if (cause != null) { - stream.println("Caused by:"); - cause.printStackTrace(stream); - } - } - - /** - * Prints this throwable and its backtrace to the specified - * print writer. - * - * @param writer {@code PrintWriter} to use for output - */ - @Override - public void printStackTrace(final PrintWriter writer) { - super.printStackTrace(writer); - if (cause != null) { - writer.println("Caused by:"); - cause.printStackTrace(writer); - } + public FileUploadException(final String message, final Throwable cause) { + super(message, cause); } }