From c4468c342efcd45bdc6cc08ea9c06ea6edd75f69 Mon Sep 17 00:00:00 2001 From: Andrew John Hughes Date: Mon, 23 Jun 2008 20:59:32 +0000 Subject: 2008-06-23 Andrew John Hughes * gnu/xml/xpath/CountFunction.java, * gnu/xml/xpath/EqualityExpr.java, * gnu/xml/xpath/Expr.java, * gnu/xml/xpath/IdFunction.java, * gnu/xml/xpath/LocalNameFunction.java, * gnu/xml/xpath/NameFunction.java, * gnu/xml/xpath/NamespaceUriFunction.java, * gnu/xml/xpath/ParenthesizedExpr.java, * gnu/xml/xpath/Steps.java, * gnu/xml/xpath/SumFunction.java, * gnu/xml/xpath/UnionExpr.java, * gnu/xml/xpath/XPathParser.java, * gnu/xml/xpath/XPathParser.y, * java/lang/Enum.java, * java/lang/reflect/Constructor.java, * java/lang/reflect/Field.java, * java/lang/reflect/Method.java: Reduce scope of unchecked warning suppression, and remove unneeded uses. --- ChangeLog | 22 +++++++++++++++++ gnu/xml/xpath/CountFunction.java | 4 ++-- gnu/xml/xpath/EqualityExpr.java | 20 +++++++++++----- gnu/xml/xpath/Expr.java | 34 +++++++++++++++++--------- gnu/xml/xpath/IdFunction.java | 3 +-- gnu/xml/xpath/LocalNameFunction.java | 4 +++- gnu/xml/xpath/NameFunction.java | 15 ++++++++---- gnu/xml/xpath/NamespaceUriFunction.java | 10 ++++---- gnu/xml/xpath/ParenthesizedExpr.java | 8 +++++-- gnu/xml/xpath/Steps.java | 14 +++++++---- gnu/xml/xpath/SumFunction.java | 8 +++++-- gnu/xml/xpath/UnionExpr.java | 20 +++++++++++----- gnu/xml/xpath/XPathParser.java | 42 ++++++++++++++++++++------------- gnu/xml/xpath/XPathParser.y | 24 ++++++++++++------- java/lang/Enum.java | 5 ++-- java/lang/reflect/Constructor.java | 20 +++++++++------- java/lang/reflect/Field.java | 6 ++--- java/lang/reflect/Method.java | 10 ++++---- 18 files changed, 180 insertions(+), 89 deletions(-) diff --git a/ChangeLog b/ChangeLog index f8147af23..c8c72ebab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2008-06-23 Andrew John Hughes + + * gnu/xml/xpath/CountFunction.java, + * gnu/xml/xpath/EqualityExpr.java, + * gnu/xml/xpath/Expr.java, + * gnu/xml/xpath/IdFunction.java, + * gnu/xml/xpath/LocalNameFunction.java, + * gnu/xml/xpath/NameFunction.java, + * gnu/xml/xpath/NamespaceUriFunction.java, + * gnu/xml/xpath/ParenthesizedExpr.java, + * gnu/xml/xpath/Steps.java, + * gnu/xml/xpath/SumFunction.java, + * gnu/xml/xpath/UnionExpr.java, + * gnu/xml/xpath/XPathParser.java, + * gnu/xml/xpath/XPathParser.y, + * java/lang/Enum.java, + * java/lang/reflect/Constructor.java, + * java/lang/reflect/Field.java, + * java/lang/reflect/Method.java: + Reduce scope of unchecked warning suppression, + and remove unneeded uses. + 2008-06-23 Christian Thalinger * include/jni.h [__cplusplus] (_Jv_JNIEnv): Renamed member p to diff --git a/gnu/xml/xpath/CountFunction.java b/gnu/xml/xpath/CountFunction.java index 25bbfa636..f29d83310 100644 --- a/gnu/xml/xpath/CountFunction.java +++ b/gnu/xml/xpath/CountFunction.java @@ -64,11 +64,11 @@ final class CountFunction this.arg = arg; } - @Override @SuppressWarnings("unchecked") + @Override public Object evaluate(Node context, int pos, int len) { Object val = arg.evaluate(context, pos, len); - return new Double((double) ((Collection) val).size()); + return new Double((double) ((Collection) val).size()); } public Expr clone(Object context) diff --git a/gnu/xml/xpath/EqualityExpr.java b/gnu/xml/xpath/EqualityExpr.java index 0a8147d76..3b6fd568a 100644 --- a/gnu/xml/xpath/EqualityExpr.java +++ b/gnu/xml/xpath/EqualityExpr.java @@ -76,7 +76,6 @@ final class EqualityExpr } } - @SuppressWarnings("unchecked") private boolean evaluateImpl(Node context, int pos, int len) { Object left = lhs.evaluate(context, pos, len); @@ -92,8 +91,11 @@ final class EqualityExpr boolean frns = right instanceof Collection; if (flns && frns) { - Collection lns = (Collection) left; - Collection rns = (Collection) right; + /* Suppression is safe, as we know context produces Collection */ + @SuppressWarnings("unchecked") + Collection lns = (Collection) left; + @SuppressWarnings("unchecked") + Collection rns = (Collection) right; if (lns.isEmpty()) { return false; @@ -138,7 +140,9 @@ final class EqualityExpr boolean frn = right instanceof Double; if ((flns && frn) || (frns && fln)) { - Collection ns = flns ? (Collection) left : (Collection) right; + /* Suppression is safe, as we know context produces Collection */ + @SuppressWarnings("unchecked") + Collection ns = flns ? (Collection) left : (Collection) right; double n = fln ? ((Double) left).doubleValue() : ((Double) right).doubleValue(); boolean all = true; @@ -170,7 +174,9 @@ final class EqualityExpr boolean frs = right instanceof String; if ((flns && frs) || (frns && fls)) { - Collection ns = flns ? (Collection) left : (Collection) right; + /* Suppression is safe, as we know context produces Collection */ + @SuppressWarnings("unchecked") + Collection ns = flns ? (Collection) left : (Collection) right; String s = fls ? (String) left : (String) right; boolean all = true; for (Node test : ns) @@ -200,7 +206,9 @@ final class EqualityExpr boolean frb = right instanceof Boolean; if ((flns && frb) || (frns && flb)) { - Collection ns = flns ? (Collection) left : (Collection) right; + /* Suppression is safe, as we know context produces Collection */ + @SuppressWarnings("unchecked") + Collection ns = flns ? (Collection) left : (Collection) right; boolean b = flb ? ((Boolean) left).booleanValue() : ((Boolean) right).booleanValue(); return _boolean(context, ns) == b; diff --git a/gnu/xml/xpath/Expr.java b/gnu/xml/xpath/Expr.java index 30d4baa5b..87ce3dfb6 100644 --- a/gnu/xml/xpath/Expr.java +++ b/gnu/xml/xpath/Expr.java @@ -115,7 +115,6 @@ public abstract class Expr } - @SuppressWarnings("unchecked") public Object evaluate(Object item, QName returnType) throws XPathExpressionException { @@ -144,7 +143,10 @@ public abstract class Expr { if (ret instanceof Collection) { - Collection ns = (Collection) ret; + /* Suppression is safe, as we know context + produces Collection */ + @SuppressWarnings("unchecked") + Collection ns = (Collection) ret; switch (ns.size()) { case 0: @@ -169,7 +171,12 @@ public abstract class Expr throw new XPathExpressionException("return value is not a node-set"); } if (ret != null) - ret = new ExprNodeSet((Collection) ret); + { + /* Suppression is safe, as we know context produces Collection */ + @SuppressWarnings("unchecked") + Collection nodes = (Collection) ret; + ret = new ExprNodeSet(nodes); + } } } return ret; @@ -232,13 +239,14 @@ public abstract class Expr * same document as the context node that have a unique ID equal to any of * the tokens in the list. */ - @SuppressWarnings("unchecked") public static Collection _id(Node context, Object object) { Set ret = new HashSet(); if (object instanceof Collection) { - Collection nodeSet = (Collection) object; + /* Suppression is safe, as the iteration will check each value is a Node */ + @SuppressWarnings("unchecked") + Collection nodeSet = (Collection) object; for (Iterator i = nodeSet.iterator(); i.hasNext(); ) { String string = stringValue(i.next()); @@ -343,7 +351,6 @@ public abstract class Expr /** * Implementation of the XPath string function. */ - @SuppressWarnings("unchecked") public static String _string(Node context, Object object) { if (object == null) @@ -392,7 +399,10 @@ public abstract class Expr } if (object instanceof Collection) { - Collection nodeSet = (Collection) object; + /* Suppression is safe, as we fail immediately if the + * first element is not a Node and don't use the rest */ + @SuppressWarnings("unchecked") + Collection nodeSet = (Collection) object; if (nodeSet.isEmpty()) { return ""; @@ -408,7 +418,6 @@ public abstract class Expr /** * Implementation of the XPath boolean function. */ - @SuppressWarnings("unchecked") public static boolean _boolean(Node context, Object object) { if (object instanceof Boolean) @@ -428,7 +437,7 @@ public abstract class Expr } if (object instanceof Collection) { - return ((Collection) object).size() != 0; + return ((Collection) object).size() != 0; } return false; // TODO user defined types } @@ -438,7 +447,6 @@ public abstract class Expr /** * Implementation of the XPath number function. */ - @SuppressWarnings("unchecked") public static double _number(Node context, Object object) { if (object == null) @@ -455,8 +463,12 @@ public abstract class Expr } if (object instanceof Collection) { + /* Suppression is safe, as we fail immediately if one + * of the elements is not a Node */ + @SuppressWarnings("unchecked") + Collection nodeSet = (Collection) object; // Convert node-set to string - object = stringValue((Collection) object); + object = stringValue(nodeSet); } if (object instanceof String) { diff --git a/gnu/xml/xpath/IdFunction.java b/gnu/xml/xpath/IdFunction.java index de6d3e4ba..b3d2208c8 100644 --- a/gnu/xml/xpath/IdFunction.java +++ b/gnu/xml/xpath/IdFunction.java @@ -72,11 +72,10 @@ public final class IdFunction this.arg = arg; } - @SuppressWarnings("unchecked") public boolean matches(Node context) { Object ret = evaluate(context, 1, 1); - return !((Collection) ret).isEmpty(); + return !((Collection) ret).isEmpty(); } @Override diff --git a/gnu/xml/xpath/LocalNameFunction.java b/gnu/xml/xpath/LocalNameFunction.java index a08a3df5f..dbad9d3b4 100644 --- a/gnu/xml/xpath/LocalNameFunction.java +++ b/gnu/xml/xpath/LocalNameFunction.java @@ -69,9 +69,11 @@ final class LocalNameFunction this.arg = arg; } - @Override @SuppressWarnings("unchecked") + @Override public Object evaluate(Node context, int pos, int len) { + /* Suppression is safe, as we know context produces Collection */ + @SuppressWarnings("unchecked") Collection val = (arg == null) ? Collections.singleton(context) : (Collection) arg.evaluate(context, pos, len); return _local_name(context, val); diff --git a/gnu/xml/xpath/NameFunction.java b/gnu/xml/xpath/NameFunction.java index 7eefbc25c..239a53453 100644 --- a/gnu/xml/xpath/NameFunction.java +++ b/gnu/xml/xpath/NameFunction.java @@ -77,25 +77,30 @@ final class NameFunction this.arg = arg; } - @Override @SuppressWarnings("unchecked") + @Override public Object evaluate(Node context, int pos, int len) { - Object val = (arg == null) ? Collections.singleton(context) : - arg.evaluate(context, pos, len); - return _name(context, (Collection) val); + /* Suppression is safe, as we know context produces Collection */ + @SuppressWarnings("unchecked") + Collection val = (arg == null) ? Collections.singleton(context) : + (Collection) arg.evaluate(context, pos, len); + return _name(context, val); } + @Override public Expr clone(Object context) { return new NameFunction((arg == null) ? null : arg.clone(context)); } - + + @Override public boolean references(QName var) { return (arg == null) ? false : arg.references(var); } + @Override public String toString() { return (arg == null) ? "name()" : "name(" + arg + ")"; diff --git a/gnu/xml/xpath/NamespaceUriFunction.java b/gnu/xml/xpath/NamespaceUriFunction.java index c988e2aaa..56da90f8c 100644 --- a/gnu/xml/xpath/NamespaceUriFunction.java +++ b/gnu/xml/xpath/NamespaceUriFunction.java @@ -69,12 +69,14 @@ final class NamespaceUriFunction this.arg = arg; } - @Override @SuppressWarnings("unchecked") + @Override public Object evaluate(Node context, int pos, int len) { - Object val = (arg == null) ? Collections.singleton(context) : - arg.evaluate(context, pos, len); - return _namespace_uri(context, (Collection) val); + /* Suppression is safe, as we know context produces Collection */ + @SuppressWarnings("unchecked") + Collection val = (arg == null) ? Collections.singleton(context) : + (Collection) arg.evaluate(context, pos, len); + return _namespace_uri(context, val); } public Expr clone(Object context) diff --git a/gnu/xml/xpath/ParenthesizedExpr.java b/gnu/xml/xpath/ParenthesizedExpr.java index 5ec3d2938..adadd6745 100644 --- a/gnu/xml/xpath/ParenthesizedExpr.java +++ b/gnu/xml/xpath/ParenthesizedExpr.java @@ -60,13 +60,17 @@ final class ParenthesizedExpr this.expr = expr; } - @Override @SuppressWarnings("unchecked") + @Override public Object evaluate(Node context, int pos, int len) { Object ret = expr.evaluate(context, pos, len); if (ret instanceof Collection) { - List list = new ArrayList((Collection) ret); + /* Suppression is safe, as we know context produces + Collection */ + @SuppressWarnings("unchecked") + Collection nodes = (Collection) ret; + List list = new ArrayList(nodes); Collections.sort(list, documentOrderComparator); ret = list; } diff --git a/gnu/xml/xpath/Steps.java b/gnu/xml/xpath/Steps.java index de22432c4..427fbe201 100644 --- a/gnu/xml/xpath/Steps.java +++ b/gnu/xml/xpath/Steps.java @@ -160,7 +160,7 @@ public final class Steps return Collections.emptySet(); } - @Override @SuppressWarnings("unchecked") + @Override public Object evaluate(Node context, int pos, int len) { //System.err.println(toString()+" evaluate"); @@ -172,13 +172,16 @@ public final class Steps while (val instanceof Collection && i.hasNext()) { Path rhs = (Path) i.next(); - val = rhs.evaluate(context, (Collection) val); + /* Suppression is safe, as we know context produces Collection */ + @SuppressWarnings("unchecked") + Collection nodes = (Collection) val; + val = rhs.evaluate(context, nodes); //System.err.println("\tevaluate "+rhs+" = "+val); } return val; } - @Override @SuppressWarnings("unchecked") + @Override Collection evaluate(Node context, Collection ns) { // Left to right @@ -197,7 +200,10 @@ public final class Steps Object ret = lhs.evaluate(node, pos++, len); if (ret instanceof Collection) { - acc.addAll((Collection) ret); + /* Suppression is safe, as we know context produces Collection */ + @SuppressWarnings("unchecked") + Collection nodes = (Collection) ret; + acc.addAll(nodes); } } ns = acc; diff --git a/gnu/xml/xpath/SumFunction.java b/gnu/xml/xpath/SumFunction.java index ce2989b4b..73db2a91d 100644 --- a/gnu/xml/xpath/SumFunction.java +++ b/gnu/xml/xpath/SumFunction.java @@ -66,14 +66,18 @@ final class SumFunction this.arg = arg; } - @Override @SuppressWarnings("unchecked") + @Override public Object evaluate(Node context, int pos, int len) { Object val = arg.evaluate(context, pos, len); double sum = 0.0d; if (val instanceof Collection) { - for (Node node : ((Collection) val)) + /* Suppression is safe, as we know context produces + Collection */ + @SuppressWarnings("unchecked") + Collection nodes = (Collection) val; + for (Node node : nodes) { String s = stringValue(node); sum += _number(context, s); diff --git a/gnu/xml/xpath/UnionExpr.java b/gnu/xml/xpath/UnionExpr.java index fcaee3d9b..03ae5c06d 100644 --- a/gnu/xml/xpath/UnionExpr.java +++ b/gnu/xml/xpath/UnionExpr.java @@ -74,21 +74,29 @@ public final class UnionExpr return false; } - @Override @SuppressWarnings("unchecked") + @Override public Object evaluate(Node context, int pos, int len) { Object left = lhs.evaluate(context, pos, len); Object right = rhs.evaluate(context, pos, len); + List list; if (left instanceof Collection && right instanceof Collection) { Set set = new HashSet(); - set.addAll ((Collection) left); - set.addAll ((Collection) right); - List list = new ArrayList(set); + /* Suppression is safe as addAll will check the types + of the elements and throw a ClassCastException as necessary */ + @SuppressWarnings("unchecked") + Collection l = (Collection) left; + @SuppressWarnings("unchecked") + Collection r = (Collection) right; + set.addAll (l); + set.addAll (r); + list = new ArrayList(set); Collections.sort(list, documentOrderComparator); - return list; } - return Collections.EMPTY_SET; + else + list = Collections.emptyList(); + return list; } public Expr clone(Object context) diff --git a/gnu/xml/xpath/XPathParser.java b/gnu/xml/xpath/XPathParser.java index 300f3161d..e8c8e94da 100644 --- a/gnu/xml/xpath/XPathParser.java +++ b/gnu/xml/xpath/XPathParser.java @@ -391,7 +391,6 @@ public class XPathParser @return result of the last reduction, if any. @throws yyException on irrecoverable parse error. */ - @SuppressWarnings("unchecked") public Object yyparse (yyInput yyLex) throws java.io.IOException, yyException { if (yyMax <= 0) yyMax = 256; // initial size @@ -566,20 +565,25 @@ case 9: case 10: // line 362 "XPathParser.y" { - yyVal = new Selector (Selector.CHILD, (List) yyVals[0+yyTop]); - } + @SuppressWarnings("unchecked") List tests = (List) yyVals[0+yyTop]; + yyVal = new Selector (Selector.CHILD, tests); + } break; case 11: // line 366 "XPathParser.y" { - yyVal = new Selector (Selector.ATTRIBUTE, (List) yyVals[0+yyTop]); - } + /* This is safe as we create this in one of the other cases */ + @SuppressWarnings("unchecked") List tests = (List) yyVals[0+yyTop]; + yyVal = new Selector (Selector.ATTRIBUTE, tests); + } break; case 12: // line 370 "XPathParser.y" { - yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), (List) yyVals[0+yyTop]); - } + /* This is safe as we create this in one of the other cases */ + @SuppressWarnings("unchecked") List tests = (List) yyVals[0+yyTop]; + yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), tests); + } break; case 13: // line 374 "XPathParser.y" @@ -606,10 +610,11 @@ case 15: case 16: // line 391 "XPathParser.y" { - List list = (List)yyVals[-1+yyTop]; - list.add((Test) yyVals[0+yyTop]); - yyVal = list; - } + /* This is safe as we create this in one of the other cases */ + @SuppressWarnings("unchecked") List tests = (List)yyVals[-1+yyTop]; + tests.add((Test) yyVals[0+yyTop]); + yyVal = tests; + } break; case 17: // line 415 "XPathParser.y" @@ -735,8 +740,10 @@ case 39: case 40: // line 512 "XPathParser.y" { - yyVal = lookupFunction((String) yyVals[-3+yyTop], (List) yyVals[-1+yyTop]); - } + /* This is safe as we create this below */ + @SuppressWarnings("unchecked") List exprs = (List) yyVals[-1+yyTop]; + yyVal = lookupFunction((String) yyVals[-3+yyTop], exprs); + } break; case 41: // line 519 "XPathParser.y" @@ -749,10 +756,11 @@ case 41: case 42: // line 525 "XPathParser.y" { - List list = (List) yyVals[0+yyTop]; - list.add(0, (Expr) yyVals[-2+yyTop]); - yyVal = list; - } + /* This is safe as we create this above */ + @SuppressWarnings("unchecked") List list = (List) yyVals[0+yyTop]; + list.add(0, (Expr) yyVals[-2+yyTop]); + yyVal = list; + } break; case 44: // line 535 "XPathParser.y" diff --git a/gnu/xml/xpath/XPathParser.y b/gnu/xml/xpath/XPathParser.y index 520e82384..a6d3fd130 100644 --- a/gnu/xml/xpath/XPathParser.y +++ b/gnu/xml/xpath/XPathParser.y @@ -360,15 +360,18 @@ relative_location_path: step: step_node_test { - $$ = new Selector (Selector.CHILD, (List) $1); + @SuppressWarnings("unchecked") List tests = (List) $1; + $$ = new Selector (Selector.CHILD, tests); } | AT step_node_test { - $$ = new Selector (Selector.ATTRIBUTE, (List) $2); + @SuppressWarnings("unchecked") List tests = (List) $2; + $$ = new Selector (Selector.ATTRIBUTE, tests); } | axis_name DOUBLE_COLON step_node_test { - $$ = new Selector (((Integer) $1).intValue (), (List) $3); + @SuppressWarnings("unchecked") List tests = (List) $3; + $$ = new Selector (((Integer) $1).intValue (), tests); } | DOT { @@ -391,8 +394,9 @@ step_node_test: } | step_node_test predicate { - List list = (List)$1; - list.add((Test) $2); + /* This is safe as we create this in one of the other cases */ + @SuppressWarnings("unchecked") List tests = (List)$1; + tests.add((Test) $2); $$ = list; } ; @@ -508,11 +512,14 @@ primary_expr: function_call: function_name LP RP { - $$ = lookupFunction((String) $1, Collections.emptyList()); + List emptyList = Collections.emptyList(); + $$ = lookupFunction((String) $1, emptyList); } | function_name LP argument_list RP { - $$ = lookupFunction((String) $1, (List) $3); + /* This is safe as we create this below */ + @SuppressWarnings("unchecked") List exprs = (List) $3; + $$ = lookupFunction((String) $1, (List) exprs); } ; @@ -525,7 +532,8 @@ argument_list: } | expr COMMA argument_list { - List list = (List) $3; + /* This is safe as we create this above */ + @SuppressWarnings("unchecked") List list = (List) $3; list.add(0, (Expr) $1); $$ = list; } diff --git a/java/lang/Enum.java b/java/lang/Enum.java index fa217bb67..da2e40b8e 100644 --- a/java/lang/Enum.java +++ b/java/lang/Enum.java @@ -89,7 +89,6 @@ public abstract class Enum> * @exception IllegalArgumentException when there is no value s in * the enum etype. */ - @SuppressWarnings("unchecked") public static > S valueOf(Class etype, String s) { if (etype == null || s == null) @@ -103,7 +102,9 @@ public abstract class Enum> if (! f.isEnumConstant()) throw new IllegalArgumentException(s); Class.setAccessible(f); - return (S) f.get(null); + @SuppressWarnings("unchecked") + S val = (S) f.get(null); + return val; } catch (NoSuchFieldException exception) { diff --git a/java/lang/reflect/Constructor.java b/java/lang/reflect/Constructor.java index 55b82e898..d9b7e8312 100755 --- a/java/lang/reflect/Constructor.java +++ b/java/lang/reflect/Constructor.java @@ -106,10 +106,12 @@ public final class Constructor * Gets the class that declared this constructor. * @return the class that declared this member */ - @SuppressWarnings("unchecked") public Class getDeclaringClass() { - return (Class) cons.getDeclaringClass(); + // Inescapable as the VM layer is 1.4 based. + @SuppressWarnings("unchecked") + Class declClass = (Class) cons.getDeclaringClass(); + return declClass; } /** @@ -162,7 +164,6 @@ public final class Constructor * * @return a list of the types of the constructor's parameters */ - @SuppressWarnings("unchecked") public Class[] getParameterTypes() { return (Class[]) cons.getParameterTypes(); @@ -175,7 +176,6 @@ public final class Constructor * * @return a list of the types in the constructor's throws clause */ - @SuppressWarnings("unchecked") public Class[] getExceptionTypes() { return (Class[]) cons.getExceptionTypes(); @@ -310,12 +310,14 @@ public final class Constructor * @throws ExceptionInInitializerError if construction triggered class * initialization, which then failed */ - @SuppressWarnings("unchecked") public T newInstance(Object... args) throws InstantiationException, IllegalAccessException, InvocationTargetException { - return (T) cons.construct(args); + // Inescapable as the VM layer is 1.4 based. + @SuppressWarnings("unchecked") + T ins = (T) cons.construct(args); + return ins; } /** @@ -424,10 +426,12 @@ public final class Constructor * null if no such annotation exists. * @throws NullPointerException if the annotation class is null. */ - @SuppressWarnings("unchecked") public T getAnnotation(Class annotationClass) { - return (T) cons.getAnnotation(annotationClass); + // Inescapable as the VM layer is 1.4 based. + @SuppressWarnings("unchecked") + T ann = (T) cons.getAnnotation(annotationClass); + return ann; } /** diff --git a/java/lang/reflect/Field.java b/java/lang/reflect/Field.java index 4c2c183c9..b9d928845 100644 --- a/java/lang/reflect/Field.java +++ b/java/lang/reflect/Field.java @@ -104,7 +104,6 @@ extends AccessibleObject implements Member * is a non-inherited member. * @return the class that declared this member */ - @SuppressWarnings("unchecked") public Class getDeclaringClass() { return (Class) f.getDeclaringClass(); @@ -710,10 +709,11 @@ extends AccessibleObject implements Member * null if no such annotation exists. * @throws NullPointerException if the annotation class is null. */ - @SuppressWarnings("unchecked") public T getAnnotation(Class annotationClass) { - return (T) f.getAnnotation(annotationClass); + // Inescapable as the VM layer is 1.4 based. T will erase to Annotation anyway. + @SuppressWarnings("unchecked") T ann = (T) f.getAnnotation(annotationClass); + return ann; } /** diff --git a/java/lang/reflect/Method.java b/java/lang/reflect/Method.java index e787fb3f6..0a532ddb6 100644 --- a/java/lang/reflect/Method.java +++ b/java/lang/reflect/Method.java @@ -104,7 +104,6 @@ extends AccessibleObject implements Member, GenericDeclaration * is a non-inherited member. * @return the class that declared this member */ - @SuppressWarnings("unchecked") public Class getDeclaringClass() { return (Class) m.getDeclaringClass(); @@ -167,7 +166,6 @@ extends AccessibleObject implements Member, GenericDeclaration * Gets the return type of this method. * @return the type of this method */ - @SuppressWarnings("unchecked") public Class getReturnType() { return (Class) m.getReturnType(); @@ -179,7 +177,6 @@ extends AccessibleObject implements Member, GenericDeclaration * * @return a list of the types of the method's parameters */ - @SuppressWarnings("unchecked") public Class[] getParameterTypes() { return (Class[]) m.getParameterTypes(); @@ -192,7 +189,6 @@ extends AccessibleObject implements Member, GenericDeclaration * * @return a list of the types in the method's throws clause */ - @SuppressWarnings("unchecked") public Class[] getExceptionTypes() { return (Class[]) m.getExceptionTypes(); @@ -474,10 +470,12 @@ extends AccessibleObject implements Member, GenericDeclaration * null if no such annotation exists. * @throws NullPointerException if the annotation class is null. */ - @SuppressWarnings("unchecked") public T getAnnotation(Class annotationClass) { - return (T) m.getAnnotation(annotationClass); + // Inescapable as the VM layer is 1.4 based. T will erase to Annotation anyway. + @SuppressWarnings("unchecked") + T ann = (T) m.getAnnotation(annotationClass); + return ann; } /** -- cgit v1.2.1