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

javac throws exception when compiling source file of size 1.5G

    XMLWordPrintable

Details

    • b04
    • generic
    • generic

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_112"
      Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      OSX Yosemite (10.10.5) / Darwin macbook.home 14.5.0 Darwin Kernel Version 14.5.0: Sun Sep 25 22:07:15 PDT 2016; root:xnu-2782.50.9~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      I created a small program that outputs a Java source file. If you try to compile the generated source file, the compiler throws the exception below. This may be related to the size of the source file (1.5Gb).

      java.lang.IllegalArgumentException
      at java.nio.ByteBuffer.allocate(ByteBuffer.java:334)
      at com.sun.tools.javac.util.BaseFileManager$ByteBufferCache.get(BaseFileManager.java:325)
      at com.sun.tools.javac.util.BaseFileManager.makeByteBuffer(BaseFileManager.java:294)
      at com.sun.tools.javac.file.RegularFileObject.getCharContent(RegularFileObject.java:114)
      at com.sun.tools.javac.file.RegularFileObject.getCharContent(RegularFileObject.java:53)
      at com.sun.tools.javac.main.JavaCompiler.readSource(JavaCompiler.java:602)
      at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:665)
      at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:950)
      at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:857)
      at com.sun.tools.javac.main.Main.compile(Main.java:523)
      at com.sun.tools.javac.main.Main.compile(Main.java:381)
      at com.sun.tools.javac.main.Main.compile(Main.java:370)
      at com.sun.tools.javac.main.Main.compile(Main.java:361)
      at com.sun.tools.javac.Main.compile(Main.java:56)
      at com.sun.tools.javac.Main.main(Main.java:42)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code below (change the "folder" variable to a valid directory on your computer) and then try to compile the output (namely the Performance.java file)
      -------
      import java.io.BufferedWriter;
      import java.io.FileWriter;
      import java.io.IOException;

      public class Main {

      public static void main(String[] args) throws IOException {
      final String folder = "/Users/hugo/temp/";
      try (BufferedWriter out = new BufferedWriter(
      new FileWriter(folder + "Performance.java"))
      ) {
      out.write("public class Performance {\n");
      out.write("\tpublic static int doNothing() {\n");
      out.write("\t\tint i = 0;\n");
      for (int i = 1; i < 99999999; i++) {
      out.write("\t\ti = " + i + ";\n");
      }
      }
      }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      After trying to compile the generated class, the compiler should print an error message saying that the source file has a syntax error (the compiler should NEVER throw an exception).
      ACTUAL -
      If you go to the console and try to compile the generated source file (javac Performance.java) you get the following exception:

      java.lang.IllegalArgumentException
      at java.nio.ByteBuffer.allocate(ByteBuffer.java:334)
      at com.sun.tools.javac.util.BaseFileManager$ByteBufferCache.get(BaseFileManager.java:325)
      at com.sun.tools.javac.util.BaseFileManager.makeByteBuffer(BaseFileManager.java:294)
      at com.sun.tools.javac.file.RegularFileObject.getCharContent(RegularFileObject.java:114)
      at com.sun.tools.javac.file.RegularFileObject.getCharContent(RegularFileObject.java:53)
      at com.sun.tools.javac.main.JavaCompiler.readSource(JavaCompiler.java:602)
      at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:665)
      at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:950)
      at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:857)
      at com.sun.tools.javac.main.Main.compile(Main.java:523)
      at com.sun.tools.javac.main.Main.compile(Main.java:381)
      at com.sun.tools.javac.main.Main.compile(Main.java:370)
      at com.sun.tools.javac.main.Main.compile(Main.java:361)
      at com.sun.tools.javac.Main.compile(Main.java:56)
      at com.sun.tools.javac.Main.main(Main.java:42)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      An exception has occurred in the compiler (1.8.0_112). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.IllegalArgumentException
      at java.nio.ByteBuffer.allocate(ByteBuffer.java:334)
      at com.sun.tools.javac.util.BaseFileManager$ByteBufferCache.get(BaseFileManager.java:325)
      at com.sun.tools.javac.util.BaseFileManager.makeByteBuffer(BaseFileManager.java:294)
      at com.sun.tools.javac.file.RegularFileObject.getCharContent(RegularFileObject.java:114)
      at com.sun.tools.javac.file.RegularFileObject.getCharContent(RegularFileObject.java:53)
      at com.sun.tools.javac.main.JavaCompiler.readSource(JavaCompiler.java:602)
      at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:665)
      at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:950)
      at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:857)
      at com.sun.tools.javac.main.Main.compile(Main.java:523)
      at com.sun.tools.javac.main.Main.compile(Main.java:381)
      at com.sun.tools.javac.main.Main.compile(Main.java:370)
      at com.sun.tools.javac.main.Main.compile(Main.java:361)
      at com.sun.tools.javac.Main.compile(Main.java:56)
      at com.sun.tools.javac.Main.main(Main.java:42)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      The code below generates the source file that allows you to reproduce the issue:
      -----

      import java.io.BufferedWriter;
      import java.io.FileWriter;
      import java.io.IOException;

      public class Main {

      public static void main(String[] args) throws IOException {
      final String folder = "/Users/hugo/temp/";
      try (BufferedWriter out = new BufferedWriter(
      new FileWriter(folder + "Performance.java"))
      ) {
      out.write("public class Performance {\n");
      out.write("\tpublic static int doNothing() {\n");
      out.write("\t\tint i = 0;\n");
      for (int i = 1; i < 99999999; i++) {
      out.write("\t\ti = " + i + ";\n");
      }
      }
      }
      }
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: