Fri, 06 Feb 2009 12:49:48 -0800
6794071: Provide exception superclass for UnknownFooExceptions
Reviewed-by: jjg
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/javax/lang/model/UnknownEntityException.java Fri Feb 06 12:49:48 2009 -0800 1.3 @@ -0,0 +1,57 @@ 1.4 +/* 1.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Sun designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Sun in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.26 + * have any questions. 1.27 + */ 1.28 + 1.29 +package javax.lang.model; 1.30 + 1.31 +/** 1.32 + * Superclass of exceptions which indicate that an unknown kind of 1.33 + * entity was encountered. This situation can occur if the language 1.34 + * evolves and new kinds of constructs are introduced. Subclasses of 1.35 + * this exception may be thrown by visitors to indicate that the 1.36 + * visitor was created for a prior version of the language. 1.37 + * 1.38 + * <p>A common superclass for those exceptions allows a single catch 1.39 + * block to have code handling them uniformly. 1.40 + * 1.41 + * @author Joseph D. Darcy 1.42 + * @see javax.lang.model.element.UnknownElementException 1.43 + * @see javax.lang.model.element.UnknownAnnotationValueException 1.44 + * @see javax.lang.model.type.UnknownTypeException 1.45 + * @since 1.7 1.46 + */ 1.47 +public class UnknownEntityException extends RuntimeException { 1.48 + 1.49 + private static final long serialVersionUID = 269L; 1.50 + 1.51 + /** 1.52 + * Creates a new {@code UnknownEntityException} with the specified 1.53 + * detail message. 1.54 + * 1.55 + * @param message the detail message 1.56 + */ 1.57 + protected UnknownEntityException(String message) { 1.58 + super(message); 1.59 + } 1.60 +}
2.1 --- a/src/share/classes/javax/lang/model/element/UnknownAnnotationValueException.java Fri Feb 06 10:23:57 2009 -0800 2.2 +++ b/src/share/classes/javax/lang/model/element/UnknownAnnotationValueException.java Fri Feb 06 12:49:48 2009 -0800 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 2.6 + * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -25,6 +25,8 @@ 2.11 2.12 package javax.lang.model.element; 2.13 2.14 +import javax.lang.model.UnknownEntityException; 2.15 + 2.16 /** 2.17 * Indicates that an unknown kind of annotation value was encountered. 2.18 * This can occur if the language evolves and new kinds of annotation 2.19 @@ -39,7 +41,7 @@ 2.20 * @see AnnotationValueVisitor#visitUnknown 2.21 * @since 1.6 2.22 */ 2.23 -public class UnknownAnnotationValueException extends RuntimeException { 2.24 +public class UnknownAnnotationValueException extends UnknownEntityException { 2.25 2.26 private static final long serialVersionUID = 269L; 2.27
3.1 --- a/src/share/classes/javax/lang/model/element/UnknownElementException.java Fri Feb 06 10:23:57 2009 -0800 3.2 +++ b/src/share/classes/javax/lang/model/element/UnknownElementException.java Fri Feb 06 12:49:48 2009 -0800 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 3.6 + * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -25,6 +25,8 @@ 3.11 3.12 package javax.lang.model.element; 3.13 3.14 +import javax.lang.model.UnknownEntityException; 3.15 + 3.16 /** 3.17 * Indicates that an unknown kind of element was encountered. This 3.18 * can occur if the language evolves and new kinds of elements are 3.19 @@ -38,7 +40,7 @@ 3.20 * @see ElementVisitor#visitUnknown 3.21 * @since 1.6 3.22 */ 3.23 -public class UnknownElementException extends RuntimeException { 3.24 +public class UnknownElementException extends UnknownEntityException { 3.25 3.26 private static final long serialVersionUID = 269L; 3.27
4.1 --- a/src/share/classes/javax/lang/model/type/UnknownTypeException.java Fri Feb 06 10:23:57 2009 -0800 4.2 +++ b/src/share/classes/javax/lang/model/type/UnknownTypeException.java Fri Feb 06 12:49:48 2009 -0800 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 4.6 + * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -25,6 +25,8 @@ 4.11 4.12 package javax.lang.model.type; 4.13 4.14 +import javax.lang.model.UnknownEntityException; 4.15 + 4.16 /** 4.17 * Indicates that an unknown kind of type was encountered. This can 4.18 * occur if the language evolves and new kinds of types are added to 4.19 @@ -38,7 +40,7 @@ 4.20 * @see TypeVisitor#visitUnknown 4.21 * @since 1.6 4.22 */ 4.23 -public class UnknownTypeException extends RuntimeException { 4.24 +public class UnknownTypeException extends UnknownEntityException { 4.25 4.26 private static final long serialVersionUID = 269L; 4.27
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/javac/processing/model/TestExceptions.java Fri Feb 06 12:49:48 2009 -0800 5.3 @@ -0,0 +1,55 @@ 5.4 +/* 5.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. 5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.7 + * 5.8 + * This code is free software; you can redistribute it and/or modify it 5.9 + * under the terms of the GNU General Public License version 2 only, as 5.10 + * published by the Free Software Foundation. 5.11 + * 5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 5.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 5.15 + * version 2 for more details (a copy is included in the LICENSE file that 5.16 + * accompanied this code). 5.17 + * 5.18 + * You should have received a copy of the GNU General Public License version 5.19 + * 2 along with this work; if not, write to the Free Software Foundation, 5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 5.21 + * 5.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 5.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 5.24 + * have any questions. 5.25 + */ 5.26 + 5.27 +/* 5.28 + * @test 5.29 + * @bug 6794071 5.30 + * @summary Test that exceptions have a proper parent class 5.31 + * @author Joseph D. Darcy 5.32 + */ 5.33 + 5.34 +import javax.lang.model.UnknownEntityException; 5.35 +import javax.lang.model.element.*; 5.36 +import javax.lang.model.type.*; 5.37 + 5.38 +/* 5.39 + * Verify UnknownFooExceptions can be caught with a common parent 5.40 + * exception. 5.41 + */ 5.42 +public class TestExceptions { 5.43 + public static void main(String... args) { 5.44 + RuntimeException[] exceptions = { 5.45 + new UnknownElementException((Element)null, (Object)null), 5.46 + new UnknownAnnotationValueException((AnnotationValue) null, (Object) null), 5.47 + new UnknownTypeException((TypeMirror)null, (Object)null) 5.48 + }; 5.49 + 5.50 + for(RuntimeException exception : exceptions) { 5.51 + try { 5.52 + throw exception; 5.53 + } catch (UnknownEntityException uee) { 5.54 + ; 5.55 + } 5.56 + } 5.57 + } 5.58 +}