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

jsr199:CompilationTask.call() will always return 'true' if a large java source is supplied as String

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 7
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      If a large java source is supplied as Sting without any carriage return, CompilationTask.call() will always return true.

      <Test.java>
      import java.io.*;
      import java.net.URI;
      import java.nio.CharBuffer;
      import java.util.*;
      import javax.tools.*;
      import javax.tools.JavaFileObject.Kind;
      import java.util.jar.*;

      public class Test {
          public static class StringFileObject extends SimpleJavaFileObject {
              final String code;
              public StringFileObject(String name, String code) {
                  super(URI.create(name), Kind.SOURCE);
                  this.code = code;
              }
              public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
                  return CharBuffer.wrap(code);
              }
          }
          public static void main(String... arg) throws Exception {
              List<JavaFileObject> jfos = new ArrayList<JavaFileObject>();
              StringBuffer sb = new StringBuffer();
              InputStream in = new FileInputStream(arg[0]);
              BufferedReader reader = new BufferedReader(new InputStreamReader(in));
              String line;
              while((line = reader.readLine()) != null) sb.append(line +" ");
              jfos.add(new StringFileObject(arg[0],sb.toString()));
              reader.close();
              JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
              JavaFileManager javaFileManager = javac.getStandardFileManager(null,null,null);
              DiagnosticCollector<JavaFileObject> dl = new DiagnosticCollector<JavaFileObject>();
              JavaCompiler.CompilationTask task = javac.getTask(null, javaFileManager, null,
                                            Arrays.asList("-Xlint:all"), null, jfos);
              if(task.call()) throw new Exception("Compilation success");
          }
      }
      </Test.java>

      <Foo.java>
      /*
       * %W% %E%
       *
       * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
       *
       * Redistribution and use in source and binary forms, with or without
       * modification, are permitted provided that the following conditions are met:
       *
       * -Redistribution of source code must retain the above copyright notice, this
       * list of conditions and the following disclaimer.
       *
       * -Redistribution in binary form must reproduce the above copyright notice,
       * this list of conditions and the following disclaimer in the documentation
       * and/or other materials provided with the distribution.
       *
       * Neither the name of Sun Microsystems, Inc. or the names of contributors may
       * be used to endorse or promote products derived from this software without
       * specific prior written permission.
       *
       * This software is provided "AS IS," without a warranty of any kind. ALL
       * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
       * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
       * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN")
       * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
       * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
       * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
       * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
       * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
       * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
       * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
       *
       * You acknowledge that this software is not designed, licensed or intended
       * for use in the design, construction, operation or maintenance of any
       * nuclear facility.
       */

      // This is input file for Extended diagnostic reporting.

      class TestConstructor<T,K>{
          T t;
          K k;
          public TestConstructor(T t,K k){
              this.t =t;
          }
          public TestConstructor(K k){
              this.k = k;
              this.t = null;
          }
          public TestConstructor(T t){
              this.t=t;
              this.k=null;
          }
          public void setT(T t){
              this.t=t;
              this.k=null;
          }
          public void setT(K k){
              this.k = k;
              this.t = null;
          }
          public void setT(T t,K k){
              this.t = t;
              this.k = k;
          }
      }
      class TestC<T>{
          T t;
          public <T>void setT(T t){
              this.t = t;
          }
      }
      public class Foo {
          public static void main(String... arg){
              TestC tC =new TestC();
              tC.setT();
              TestConstructor tc = new TestConstructor("saaa");
              tc.setT("sasa");
              TestC<Integer> tC1 = new TestC();
              tC1.setT(545);
          }
      }
      </Foo.java>

      Foo.java will be supplied to Test.java as String without any carriage returns, in other words total Foo.java will be supplied as single line String without any break or carriage returns. Though Foo.java has compilation error, CompilitionTask.call will return true.

      <reproduce>
      bash-3.00$ javac Test.java
      bash-3.00$ java Test Foo.java
      Exception in thread "main" java.lang.Exception: Compilation success
              at Test.main(Test.java:34)

      </reproduce>
      <java-version>
      bash-3.00$ java -version
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b09)
      Java HotSpot(TM) Client VM (build 1.7.0-ea-b09, mixed mode)
      </java-version>

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              savadhansunw Seetharama Avadhanam (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: