binary-to-string again

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

binary-to-string again

Jonathan Rowell

Hi,


looking at the code of this function, why does an exception - assuming that one takes place - get ignored :-


    protected StringValue binaryToString(BinaryValue binary, String encoding) throws XPathException {
        final ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {
            binary.streamBinaryTo(os);
            return new StringValue(new String(os.toByteArray(), encoding));
        } catch(final IOException ioe) {
            throw new XPathException(this, ioe);
        } finally {
            try {
                os.close();
            } catch(final IOException ex) {
            }
        }
    }

If os.close() actually does cause an exception - it gets silently ignored. Wouldn't it be better to log it?


regards


Jonathan



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|

Re: binary-to-string again

Adam Retter
Indeed it should be LOG.warn instead of ignored. Also this should be refactored to a try-with-resources.

On 12 Feb 2017 5:31 p.m., "Jonathan Rowell" <[hidden email]> wrote:

Hi,


looking at the code of this function, why does an exception - assuming that one takes place - get ignored :-


    protected StringValue binaryToString(BinaryValue binary, String encoding) throws XPathException {
        final ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {
            binary.streamBinaryTo(os);
            return new StringValue(new String(os.toByteArray(), encoding));
        } catch(final IOException ioe) {
            throw new XPathException(this, ioe);
        } finally {
            try {
                os.close();
            } catch(final IOException ex) {
            }
        }
    }

If os.close() actually does cause an exception - it gets silently ignored. Wouldn't it be better to log it?


regards


Jonathan



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open