JDK-6937417 : javac -Xprint returns IndexOutOfBoundsException
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6u18,7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2010-03-23
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 Other
7 b89Fixed OpenJDK6Fixed
Related Reports
Duplicate :  
Description
javac -Xprint returns IndexOutOfBoundsException on a following trivial testcase:

> cat NotFullOfAnnotations.java 

enum NotFullOfAnnotations {}

> javac -J-showversion -Xprint NotFullOfAnnotations.java 

java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)


An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.RangeCheck(ArrayList.java:547)
	at java.util.ArrayList.get(ArrayList.java:322)
	at com.sun.tools.javac.processing.PrintingProcessor$PrintingElementVisitor.visitType(PrintingProcessor.java:231)
	at com.sun.tools.javac.processing.PrintingProcessor$PrintingElementVisitor.visitType(PrintingProcessor.java:72)
	at com.sun.tools.javac.code.Symbol$ClassSymbol.accept(Symbol.java:827)
	at javax.lang.model.util.AbstractElementVisitor6.visit(AbstractElementVisitor6.java:85)
	at com.sun.tools.javac.processing.PrintingProcessor.print(PrintingProcessor.java:65)
	at com.sun.tools.javac.processing.PrintingProcessor.process(PrintingProcessor.java:57)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:624)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:553)
	at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:698)
	at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:981)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
	at com.sun.tools.javac.main.Main.compile(Main.java:353)
	at com.sun.tools.javac.main.Main.compile(Main.java:279)
	at com.sun.tools.javac.main.Main.compile(Main.java:270)
	at com.sun.tools.javac.Main.compile(Main.java:69)
	at com.sun.tools.javac.Main.main(Main.java:54)

Comments
SUGGESTED FIX # HG changeset patch # User darcy # Date 1269475355 25200 # Node ID 65e422bbb9841febf9bfa706322b0870711fe6a0 # Parent 3058880c0b8da120a932131829d7bb22323bd671 6937417: javac -Xprint returns IndexOutOfBoundsException Reviewed-by: jjg --- a/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Wed Mar 24 12:18:17 2010 -0700 +++ b/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Wed Mar 24 17:02:35 2010 -0700 @@ -229,23 +229,24 @@ public class PrintingProcessor extends A if (kind == ENUM) { List<Element> enclosedElements = new ArrayList<Element>(e.getEnclosedElements()); + // Handle any enum constants specially before other entities. List<Element> enumConstants = new ArrayList<Element>(); for(Element element : enclosedElements) { if (element.getKind() == ENUM_CONSTANT) enumConstants.add(element); } - - int i; - for(i = 0; i < enumConstants.size()-1; i++) { + if (!enumConstants.isEmpty()) { + int i; + for(i = 0; i < enumConstants.size()-1; i++) { + this.visit(enumConstants.get(i), true); + writer.print(","); + } this.visit(enumConstants.get(i), true); - writer.print(","); - } - if (i >= 0 ) { - this.visit(enumConstants.get(i), true); - writer.print(";"); - } - - enclosedElements.removeAll(enumConstants); + writer.println(";\n"); + + enclosedElements.removeAll(enumConstants); + } + for(Element element : enclosedElements) this.visit(element); } else { --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/model/util/elements/VacuousEnum.java Wed Mar 24 17:02:35 2010 -0700 @@ -0,0 +1,33 @@ +/* + * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6937417 + * @summary Test -Xprint on enum type with no constants + * @author Joseph D. Darcy + * @compile -Xprint VacuousEnum.java + */ +public enum VacuousEnum { + // But alas, no enum constants! +}
25-03-2010

PUBLIC COMMENTS See http://hg.openjdk.java.net/jdk7/tl-gate/langtools/rev/65e422bbb984
25-03-2010

EVALUATION Yes, crashes are bad, even when just printing.
24-03-2010