You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Tim Allison <ta...@apache.org> on 2023/09/22 13:04:18 UTC

DirectoryNode's getEntry() and IllegalArgumentException

All,
  First, I'm not proposing any changes for 5.2.4 (many thanks PJ for
running the release!).

  In looking at DirectoryNode's getEntry, I see this:

@Override
public Entry getEntry(final String name) throws FileNotFoundException {
    Entry rval = null;

    if (name != null) {
        rval = _byname.get(name);
    }
    if (rval == null) {
        // throw more useful exceptions for known wrong file-extensions
        if(_byname.containsKey("Workbook")) {
            throw new IllegalArgumentException("The document is really
a XLS file");
        } else if(_byname.containsKey("PowerPoint Document")) {
            throw new IllegalArgumentException("The document is really
a PPT file");
        } else if(_byname.containsKey("VisioDocument")) {
            throw new IllegalArgumentException("The document is really
a VSD file");
        }

        // either a null name was given, or there is no such name
        throw new FileNotFoundException("no such entry: \"" + name
                + "\", had: " + _byname.keySet());
    }
    return rval;
}

I blindly copied this logic into getEntryCaseInsenstive.  Does anyone
remember/know how the IllegalArgumentExceptions are more useful than
the FNFE?

If this is a general DirectoryNode for OLE2, shouldn't an fnfe be the
right answer no matter whether its a ppt or xls or vsd?

Thank you!

Best,

            Tim

Re: DirectoryNode's getEntry() and IllegalArgumentException

Posted by Dominik Stadler <do...@gmx.at>.
Hi,

Seems I added this back in 2019, but I cannot remember why :(.

Commit-message says "Adjust handling of some exceptions in regression tests"

I assume I tried to give more user-readable error messages for cases where
a document has an incorrect extension.

Dominik.


On Fri, Sep 22, 2023 at 3:04 PM Tim Allison <ta...@apache.org> wrote:

> All,
>   First, I'm not proposing any changes for 5.2.4 (many thanks PJ for
> running the release!).
>
>   In looking at DirectoryNode's getEntry, I see this:
>
> @Override
> public Entry getEntry(final String name) throws FileNotFoundException {
>     Entry rval = null;
>
>     if (name != null) {
>         rval = _byname.get(name);
>     }
>     if (rval == null) {
>         // throw more useful exceptions for known wrong file-extensions
>         if(_byname.containsKey("Workbook")) {
>             throw new IllegalArgumentException("The document is really
> a XLS file");
>         } else if(_byname.containsKey("PowerPoint Document")) {
>             throw new IllegalArgumentException("The document is really
> a PPT file");
>         } else if(_byname.containsKey("VisioDocument")) {
>             throw new IllegalArgumentException("The document is really
> a VSD file");
>         }
>
>         // either a null name was given, or there is no such name
>         throw new FileNotFoundException("no such entry: \"" + name
>                 + "\", had: " + _byname.keySet());
>     }
>     return rval;
> }
>
> I blindly copied this logic into getEntryCaseInsenstive.  Does anyone
> remember/know how the IllegalArgumentExceptions are more useful than
> the FNFE?
>
> If this is a general DirectoryNode for OLE2, shouldn't an fnfe be the
> right answer no matter whether its a ppt or xls or vsd?
>
> Thank you!
>
> Best,
>
>             Tim
>