Wed, 24 Mar 2010 17:02:35 -0700
6937417: javac -Xprint returns IndexOutOfBoundsException
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Wed Mar 24 12:18:17 2010 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Wed Mar 24 17:02:35 2010 -0700 1.3 @@ -229,23 +229,24 @@ 1.4 if (kind == ENUM) { 1.5 List<Element> enclosedElements = 1.6 new ArrayList<Element>(e.getEnclosedElements()); 1.7 + // Handle any enum constants specially before other entities. 1.8 List<Element> enumConstants = new ArrayList<Element>(); 1.9 for(Element element : enclosedElements) { 1.10 if (element.getKind() == ENUM_CONSTANT) 1.11 enumConstants.add(element); 1.12 } 1.13 + if (!enumConstants.isEmpty()) { 1.14 + int i; 1.15 + for(i = 0; i < enumConstants.size()-1; i++) { 1.16 + this.visit(enumConstants.get(i), true); 1.17 + writer.print(","); 1.18 + } 1.19 + this.visit(enumConstants.get(i), true); 1.20 + writer.println(";\n"); 1.21 1.22 - int i; 1.23 - for(i = 0; i < enumConstants.size()-1; i++) { 1.24 - this.visit(enumConstants.get(i), true); 1.25 - writer.print(","); 1.26 - } 1.27 - if (i >= 0 ) { 1.28 - this.visit(enumConstants.get(i), true); 1.29 - writer.print(";"); 1.30 + enclosedElements.removeAll(enumConstants); 1.31 } 1.32 1.33 - enclosedElements.removeAll(enumConstants); 1.34 for(Element element : enclosedElements) 1.35 this.visit(element); 1.36 } else {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/processing/model/util/elements/VacuousEnum.java Wed Mar 24 17:02:35 2010 -0700 2.3 @@ -0,0 +1,33 @@ 2.4 +/* 2.5 + * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 2.24 + * have any questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 6937417 2.30 + * @summary Test -Xprint on enum type with no constants 2.31 + * @author Joseph D. Darcy 2.32 + * @compile -Xprint VacuousEnum.java 2.33 + */ 2.34 +public enum VacuousEnum { 2.35 + // But alas, no enum constants! 2.36 +}