question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BaseEncoding.encodingStream().close() is non-idempotent

See original GitHub issue

Closeable.close says:

If the stream is already closed then invoking this method has no effect.

Code:

StringWriter w = new StringWriter();
OutputStream out = BaseEncoding.base64().encodingStream(w);
out.write(0);
out.close();
System.out.println(w);
out.close();
System.out.println(w);

Output:

AA==
AA==A===

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
swankjessecommented, Oct 16, 2020

Being idempotent is useful; it’s very easy to double-close a stream due to ARM blocks and wrapping streams that close their underlying streams.

Synchronization is probably unnecessary. Java I/O streams are generally synchronized, but I’ve never seen anyone use multiple threads to concurrently read or write a shared stream.

1reaction
brettkail-wkcommented, Oct 16, 2020

It looks like the problem is just that close doesn’t adjust bitBufferLength. I don’t think thread-safety is required.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[gs-commits] ghostpdl annotated tag, ghostscript-9.20, created ...
Bug 692026: Replace vsprintf() with vsnprintf() Fix Cygwin build. ... Bug 693279: font: default base encoding Bug 692750: have gdevwpr2 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found