Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8286579

Re-examine synchronization of mark and reset methods on InflaterInputStream

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • core-libs
    • None
    • behavioral
    • minimal
    • Given the current implementation of these methods, removing the synchronization shouldn't cause any compatibility issues.
    • Java API
    • SE

      Summary

      Remove synchronized from mark and reset methods of InflaterInputStream

      Problem

      The mark and reset methods of java.util.zip.InflaterInputStream are marked as synchronized. However, the implementation of mark is a no-op and the implementation of reset always throws an IOException. Both these methods don't need to be synchronized.

      Solution

      Remove the synchronization on these methods.

      Specification

      diff --git a/src/java.base/share/classes/java/util/zip/InflaterInputStream.java b/src/java.base/share/classes/java/util/zip/InflaterInputStream.java
      index a87f78b38381..998676d94a55 100644
      --- a/src/java.base/share/classes/java/util/zip/InflaterInputStream.java
      +++ b/src/java.base/share/classes/java/util/zip/InflaterInputStream.java
      @@ -264,21 +264,22 @@ public boolean markSupported() {
           /**
            * Marks the current position in this input stream.
            *
      -     * <p> The {@code mark} method of {@code InflaterInputStream}
      +     * @implSpec The {@code mark} method of {@code InflaterInputStream}
            * does nothing.
            *
            * @param   readlimit   the maximum limit of bytes that can be read before
            *                      the mark position becomes invalid.
            * @see     java.io.InputStream#reset()
            */
      -    public synchronized void mark(int readlimit) {
      +    @Override
      +    public void mark(int readlimit) {
           }
      
           /**
            * Repositions this stream to the position at the time the
            * {@code mark} method was last called on this input stream.
            *
      -     * <p> The method {@code reset} for class
      +     * @implSpec The method {@code reset} for class
            * {@code InflaterInputStream} does nothing except throw an
            * {@code IOException}.
            *
      @@ -286,7 +287,8 @@ public synchronized void mark(int readlimit) {
            * @see     java.io.InputStream#mark(int)
            * @see     java.io.IOException
            */
      -    public synchronized void reset() throws IOException {
      +    @Override
      +    public void reset() throws IOException {
               throw new IOException("mark/reset not supported");
           }
       }

            jpai Jaikiran Pai
            jpai Jaikiran Pai
            Lance Andersen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: