I manage a Tomcat/JSP webapp.  We are updating our source code to conform
to the recent `javax` -> `jakarta` namespace change in the Servlet package.

The app uses the Apache Commons FileUpload package, which must be upgraded
from v1 to v2 as part of this change.

FileUpload v1 contains a `DiskFileItem` class:
```
org.apache.commons.fileupload.disk.DiskFileItem
```

FileUpload v2 contains the corresponding class
```
org.apache.commons.fileupload2.core.DiskFileItem
```

Our webapp code, written for v1, extends `DiskFileItem`:
```
public class MonitoredDiskFileItem extends DiskFileItem
{
    private MonitoredOutputStream mos = null;
    private OutputStreamListener listener;

    public MonitoredDiskFileItem(String fieldName, String contentType,
boolean isFormField, String fileName, int sizeThreshold, File repository,
OutputStreamListener listener)
    {
        super(fieldName, contentType, isFormField, fileName, sizeThreshold,
repository);
        this.listener = listener;
    }

    public OutputStream getOutputStream() throws IOException
    {
        if (mos == null)
        {
            mos = new MonitoredOutputStream(super.getOutputStream(),
listener);
        }
        return mos;
    }
}
```

This breaks with the update to v2 with `error: cannot inherit from final
DiskFileItem` because the `DiskFileItem` class was changed to `final`
across versions.

The migration guide at
https://commons.apache.org/proper/commons-fileupload/migration.html doesn't
give guidance at this level of detail.

Is there anything I can do to salvage this code?  I know that I could
compile my own version of the source code without the `final` keyword in
`DiskFileItem.class`, but I have to assume there's a reason for it and that
it would break other aspects of the code.  I hope very much that there's a
simpler solution.  I'm a system administrator, not a programmer, so I
cannot rewrite the package from scratch.

Thanks,
Joel

Reply via email to