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

Suspicious buffer allocation in com.sun.tools.javac.file.BaseFileManager

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      On line 465 of BaseFileManager.java (http://hg.openjdk.java.net/jdk9/dev/langtools/file/2aa0433e0add/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java#l465) I found the following piece of code:

          ByteBuffer.allocate(capacity + capacity>>1)

      Whitespace suggests that the new capacity is meant to be parsed as "capacity + (capacity>>1)". In fact, however, ">>" binds less tightly than "+" (cf., e.g., https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html), so this is parsed as "(capacity + capacity) >> 1", meaning that the new capacity is the same as the old capacity (except if there is an overflow), which seems unlikely to be the intended behaviour.

      The obvious fix would be to introduce parentheses:

          ByteBuffer.allocate(capacity + (capacity>>1))


      REPRODUCIBILITY :
      This bug can be reproduced always.

        Attachments

          Activity

            People

            • Assignee:
              sadayapalam Srikanth Adayapalam
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: