This patch limits the scope of the @SuppressWarnings annotation, where used, to just the line in question. It also removes a number of cases where suppression is needed because the cast is valid (from a raw type to an unbounded wildcard type). Thanks to Joshua Bloch's second edition of Effective Java for pointing out these cases.
ChangeLog: 2008-06-23 Andrew John Hughes <[EMAIL PROTECTED]> * 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. -- Andrew :) Support Free Java! Contribute to GNU Classpath and the OpenJDK http://www.gnu.org/software/classpath http://openjdk.java.net PGP Key: 94EFD9D8 (http://subkeys.pgp.net) Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8
Index: gnu/xml/xpath/CountFunction.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/CountFunction.java,v retrieving revision 1.4 diff -u -u -r1.4 CountFunction.java --- gnu/xml/xpath/CountFunction.java 22 Jun 2008 22:33:22 -0000 1.4 +++ gnu/xml/xpath/CountFunction.java 23 Jun 2008 20:42:32 -0000 @@ -64,11 +64,11 @@ 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<Node>) val).size()); + return new Double((double) ((Collection<?>) val).size()); } public Expr clone(Object context) Index: gnu/xml/xpath/EqualityExpr.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/EqualityExpr.java,v retrieving revision 1.5 diff -u -u -r1.5 EqualityExpr.java --- gnu/xml/xpath/EqualityExpr.java 22 Jun 2008 22:33:22 -0000 1.5 +++ gnu/xml/xpath/EqualityExpr.java 23 Jun 2008 20:42:32 -0000 @@ -76,7 +76,6 @@ } } - @SuppressWarnings("unchecked") private boolean evaluateImpl(Node context, int pos, int len) { Object left = lhs.evaluate(context, pos, len); @@ -92,8 +91,11 @@ boolean frns = right instanceof Collection; if (flns && frns) { - Collection<Node> lns = (Collection<Node>) left; - Collection<Node> rns = (Collection<Node>) right; + /* Suppression is safe, as we know context produces Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> lns = (Collection<Node>) left; + @SuppressWarnings("unchecked") + Collection<Node> rns = (Collection<Node>) right; if (lns.isEmpty()) { return false; @@ -138,7 +140,9 @@ boolean frn = right instanceof Double; if ((flns && frn) || (frns && fln)) { - Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right; + /* Suppression is safe, as we know context produces Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right; double n = fln ? ((Double) left).doubleValue() : ((Double) right).doubleValue(); boolean all = true; @@ -170,7 +174,9 @@ boolean frs = right instanceof String; if ((flns && frs) || (frns && fls)) { - Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right; + /* Suppression is safe, as we know context produces Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right; String s = fls ? (String) left : (String) right; boolean all = true; for (Node test : ns) @@ -200,7 +206,9 @@ boolean frb = right instanceof Boolean; if ((flns && frb) || (frns && flb)) { - Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right; + /* Suppression is safe, as we know context produces Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right; boolean b = flb ? ((Boolean) left).booleanValue() : ((Boolean) right).booleanValue(); return _boolean(context, ns) == b; Index: gnu/xml/xpath/Expr.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/Expr.java,v retrieving revision 1.10 diff -u -u -r1.10 Expr.java --- gnu/xml/xpath/Expr.java 22 Jun 2008 22:33:22 -0000 1.10 +++ gnu/xml/xpath/Expr.java 23 Jun 2008 20:42:34 -0000 @@ -115,7 +115,6 @@ } - @SuppressWarnings("unchecked") public Object evaluate(Object item, QName returnType) throws XPathExpressionException { @@ -144,7 +143,10 @@ { if (ret instanceof Collection) { - Collection<Node> ns = (Collection<Node>) ret; + /* Suppression is safe, as we know context + produces Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> ns = (Collection<Node>) ret; switch (ns.size()) { case 0: @@ -169,7 +171,12 @@ throw new XPathExpressionException("return value is not a node-set"); } if (ret != null) - ret = new ExprNodeSet((Collection<Node>) ret); + { + /* Suppression is safe, as we know context produces Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> nodes = (Collection<Node>) ret; + ret = new ExprNodeSet(nodes); + } } } return ret; @@ -232,13 +239,14 @@ * 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<Node> _id(Node context, Object object) { Set<Node> ret = new HashSet<Node>(); if (object instanceof Collection) { - Collection<Node> nodeSet = (Collection<Node>) object; + /* Suppression is safe, as the iteration will check each value is a Node */ + @SuppressWarnings("unchecked") + Collection<Node> nodeSet = (Collection<Node>) object; for (Iterator<Node> i = nodeSet.iterator(); i.hasNext(); ) { String string = stringValue(i.next()); @@ -343,7 +351,6 @@ /** * Implementation of the XPath <code>string</code> function. */ - @SuppressWarnings("unchecked") public static String _string(Node context, Object object) { if (object == null) @@ -392,7 +399,10 @@ } if (object instanceof Collection) { - Collection<Node> nodeSet = (Collection<Node>) 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<Node> nodeSet = (Collection<Node>) object; if (nodeSet.isEmpty()) { return ""; @@ -408,7 +418,6 @@ /** * Implementation of the XPath <code>boolean</code> function. */ - @SuppressWarnings("unchecked") public static boolean _boolean(Node context, Object object) { if (object instanceof Boolean) @@ -428,7 +437,7 @@ } if (object instanceof Collection) { - return ((Collection<Node>) object).size() != 0; + return ((Collection<?>) object).size() != 0; } return false; // TODO user defined types } @@ -438,7 +447,6 @@ /** * Implementation of the XPath <code>number</code> function. */ - @SuppressWarnings("unchecked") public static double _number(Node context, Object object) { if (object == null) @@ -455,8 +463,12 @@ } if (object instanceof Collection) { + /* Suppression is safe, as we fail immediately if one + * of the elements is not a Node */ + @SuppressWarnings("unchecked") + Collection<Node> nodeSet = (Collection<Node>) object; // Convert node-set to string - object = stringValue((Collection<Node>) object); + object = stringValue(nodeSet); } if (object instanceof String) { Index: gnu/xml/xpath/IdFunction.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/IdFunction.java,v retrieving revision 1.5 diff -u -u -r1.5 IdFunction.java --- gnu/xml/xpath/IdFunction.java 22 Jun 2008 22:33:22 -0000 1.5 +++ gnu/xml/xpath/IdFunction.java 23 Jun 2008 20:42:34 -0000 @@ -72,11 +72,10 @@ this.arg = arg; } - @SuppressWarnings("unchecked") public boolean matches(Node context) { Object ret = evaluate(context, 1, 1); - return !((Collection<Node>) ret).isEmpty(); + return !((Collection<?>) ret).isEmpty(); } @Override Index: gnu/xml/xpath/LocalNameFunction.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/LocalNameFunction.java,v retrieving revision 1.6 diff -u -u -r1.6 LocalNameFunction.java --- gnu/xml/xpath/LocalNameFunction.java 22 Jun 2008 22:33:22 -0000 1.6 +++ gnu/xml/xpath/LocalNameFunction.java 23 Jun 2008 20:42:34 -0000 @@ -69,9 +69,11 @@ 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<Node> */ + @SuppressWarnings("unchecked") Collection<Node> val = (arg == null) ? Collections.singleton(context) : (Collection<Node>) arg.evaluate(context, pos, len); return _local_name(context, val); Index: gnu/xml/xpath/NameFunction.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/NameFunction.java,v retrieving revision 1.6 diff -u -u -r1.6 NameFunction.java --- gnu/xml/xpath/NameFunction.java 22 Jun 2008 22:33:22 -0000 1.6 +++ gnu/xml/xpath/NameFunction.java 23 Jun 2008 20:42:34 -0000 @@ -77,25 +77,30 @@ 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<Node>) val); + /* Suppression is safe, as we know context produces Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> val = (arg == null) ? Collections.singleton(context) : + (Collection<Node>) 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 + ")"; Index: gnu/xml/xpath/NamespaceUriFunction.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/NamespaceUriFunction.java,v retrieving revision 1.5 diff -u -u -r1.5 NamespaceUriFunction.java --- gnu/xml/xpath/NamespaceUriFunction.java 22 Jun 2008 21:21:11 -0000 1.5 +++ gnu/xml/xpath/NamespaceUriFunction.java 23 Jun 2008 20:42:34 -0000 @@ -69,12 +69,14 @@ 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<Node>) val); + /* Suppression is safe, as we know context produces Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> val = (arg == null) ? Collections.singleton(context) : + (Collection<Node>) arg.evaluate(context, pos, len); + return _namespace_uri(context, val); } public Expr clone(Object context) Index: gnu/xml/xpath/ParenthesizedExpr.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/ParenthesizedExpr.java,v retrieving revision 1.5 diff -u -u -r1.5 ParenthesizedExpr.java --- gnu/xml/xpath/ParenthesizedExpr.java 22 Jun 2008 22:33:22 -0000 1.5 +++ gnu/xml/xpath/ParenthesizedExpr.java 23 Jun 2008 20:42:34 -0000 @@ -60,13 +60,17 @@ 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<Node> list = new ArrayList<Node>((Collection<Node>) ret); + /* Suppression is safe, as we know context produces + Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> nodes = (Collection<Node>) ret; + List<Node> list = new ArrayList<Node>(nodes); Collections.sort(list, documentOrderComparator); ret = list; } Index: gnu/xml/xpath/Steps.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/Steps.java,v retrieving revision 1.6 diff -u -u -r1.6 Steps.java --- gnu/xml/xpath/Steps.java 22 Jun 2008 21:21:11 -0000 1.6 +++ gnu/xml/xpath/Steps.java 23 Jun 2008 20:42:34 -0000 @@ -160,7 +160,7 @@ 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 @@ while (val instanceof Collection && i.hasNext()) { Path rhs = (Path) i.next(); - val = rhs.evaluate(context, (Collection<Node>) val); + /* Suppression is safe, as we know context produces Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> nodes = (Collection<Node>) val; + val = rhs.evaluate(context, nodes); //System.err.println("\tevaluate "+rhs+" = "+val); } return val; } - @Override @SuppressWarnings("unchecked") + @Override Collection<Node> evaluate(Node context, Collection<Node> ns) { // Left to right @@ -197,7 +200,10 @@ Object ret = lhs.evaluate(node, pos++, len); if (ret instanceof Collection) { - acc.addAll((Collection<Node>) ret); + /* Suppression is safe, as we know context produces Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> nodes = (Collection<Node>) ret; + acc.addAll(nodes); } } ns = acc; Index: gnu/xml/xpath/SumFunction.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/SumFunction.java,v retrieving revision 1.4 diff -u -u -r1.4 SumFunction.java --- gnu/xml/xpath/SumFunction.java 22 Jun 2008 19:43:01 -0000 1.4 +++ gnu/xml/xpath/SumFunction.java 23 Jun 2008 20:42:34 -0000 @@ -66,14 +66,18 @@ 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<Node>) val)) + /* Suppression is safe, as we know context produces + Collection<Node> */ + @SuppressWarnings("unchecked") + Collection<Node> nodes = (Collection<Node>) val; + for (Node node : nodes) { String s = stringValue(node); sum += _number(context, s); Index: gnu/xml/xpath/UnionExpr.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/UnionExpr.java,v retrieving revision 1.4 diff -u -u -r1.4 UnionExpr.java --- gnu/xml/xpath/UnionExpr.java 22 Jun 2008 19:43:02 -0000 1.4 +++ gnu/xml/xpath/UnionExpr.java 23 Jun 2008 20:42:34 -0000 @@ -74,21 +74,29 @@ 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<Node> list; if (left instanceof Collection && right instanceof Collection) { Set<Node> set = new HashSet<Node>(); - set.addAll ((Collection<Node>) left); - set.addAll ((Collection<Node>) right); - List<Node> list = new ArrayList<Node>(set); + /* Suppression is safe as addAll will check the types + of the elements and throw a ClassCastException as necessary */ + @SuppressWarnings("unchecked") + Collection<Node> l = (Collection<Node>) left; + @SuppressWarnings("unchecked") + Collection<Node> r = (Collection<Node>) right; + set.addAll (l); + set.addAll (r); + list = new ArrayList<Node>(set); Collections.sort(list, documentOrderComparator); - return list; } - return Collections.EMPTY_SET; + else + list = Collections.emptyList(); + return list; } public Expr clone(Object context) Index: gnu/xml/xpath/XPathParser.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/XPathParser.java,v retrieving revision 1.7 diff -u -u -r1.7 XPathParser.java --- gnu/xml/xpath/XPathParser.java 22 Jun 2008 19:43:02 -0000 1.7 +++ gnu/xml/xpath/XPathParser.java 23 Jun 2008 20:42:35 -0000 @@ -391,7 +391,6 @@ @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 10: // line 362 "XPathParser.y" { - yyVal = new Selector (Selector.CHILD, (List<Test>) yyVals[0+yyTop]); - } + @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) yyVals[0+yyTop]; + yyVal = new Selector (Selector.CHILD, tests); + } break; case 11: // line 366 "XPathParser.y" { - yyVal = new Selector (Selector.ATTRIBUTE, (List<Test>) yyVals[0+yyTop]); - } + /* This is safe as we create this in one of the other cases */ + @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) 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<Test>) yyVals[0+yyTop]); - } + /* This is safe as we create this in one of the other cases */ + @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) yyVals[0+yyTop]; + yyVal = new Selector (((Integer) yyVals[-2+yyTop]).intValue (), tests); + } break; case 13: // line 374 "XPathParser.y" @@ -606,10 +610,11 @@ case 16: // line 391 "XPathParser.y" { - List<Test> list = (List<Test>)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<Test> tests = (List<Test>)yyVals[-1+yyTop]; + tests.add((Test) yyVals[0+yyTop]); + yyVal = tests; + } break; case 17: // line 415 "XPathParser.y" @@ -735,8 +740,10 @@ 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<Expr> exprs = (List<Expr>) yyVals[-1+yyTop]; + yyVal = lookupFunction((String) yyVals[-3+yyTop], exprs); + } break; case 41: // line 519 "XPathParser.y" @@ -749,10 +756,11 @@ case 42: // line 525 "XPathParser.y" { - List<Expr> list = (List<Expr>) yyVals[0+yyTop]; - list.add(0, (Expr) yyVals[-2+yyTop]); - yyVal = list; - } + /* This is safe as we create this above */ + @SuppressWarnings("unchecked") List<Expr> list = (List<Expr>) yyVals[0+yyTop]; + list.add(0, (Expr) yyVals[-2+yyTop]); + yyVal = list; + } break; case 44: // line 535 "XPathParser.y" Index: gnu/xml/xpath/XPathParser.y =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/XPathParser.y,v retrieving revision 1.5 diff -u -u -r1.5 XPathParser.y --- gnu/xml/xpath/XPathParser.y 22 Jun 2008 19:43:02 -0000 1.5 +++ gnu/xml/xpath/XPathParser.y 23 Jun 2008 20:42:35 -0000 @@ -360,15 +360,18 @@ step: step_node_test { - $$ = new Selector (Selector.CHILD, (List) $1); + @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) $1; + $$ = new Selector (Selector.CHILD, tests); } | AT step_node_test { - $$ = new Selector (Selector.ATTRIBUTE, (List) $2); + @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) $2; + $$ = new Selector (Selector.ATTRIBUTE, tests); } | axis_name DOUBLE_COLON step_node_test { - $$ = new Selector (((Integer) $1).intValue (), (List) $3); + @SuppressWarnings("unchecked") List<Test> tests = (List<Test>) $3; + $$ = new Selector (((Integer) $1).intValue (), tests); } | DOT { @@ -391,8 +394,9 @@ } | step_node_test predicate { - List<Test> list = (List<Test>)$1; - list.add((Test) $2); + /* This is safe as we create this in one of the other cases */ + @SuppressWarnings("unchecked") List<Test> tests = (List<Test>)$1; + tests.add((Test) $2); $$ = list; } ; @@ -508,11 +512,14 @@ function_call: function_name LP RP { - $$ = lookupFunction((String) $1, Collections.emptyList()); + List<Expr> 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<Expr> exprs = (List<Expr>) $3; + $$ = lookupFunction((String) $1, (List) exprs); } ; @@ -525,7 +532,8 @@ } | expr COMMA argument_list { - List<Expr> list = (List<Expr>) $3; + /* This is safe as we create this above */ + @SuppressWarnings("unchecked") List<Expr> list = (List<Expr>) $3; list.add(0, (Expr) $1); $$ = list; } Index: java/lang/Enum.java =================================================================== RCS file: /sources/classpath/classpath/java/lang/Enum.java,v retrieving revision 1.7 diff -u -u -r1.7 Enum.java --- java/lang/Enum.java 4 Feb 2007 09:58:00 -0000 1.7 +++ java/lang/Enum.java 23 Jun 2008 20:42:36 -0000 @@ -89,7 +89,6 @@ * @exception IllegalArgumentException when there is no value s in * the enum etype. */ - @SuppressWarnings("unchecked") public static <S extends Enum<S>> S valueOf(Class<S> etype, String s) { if (etype == null || s == null) @@ -103,7 +102,9 @@ 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) { Index: java/lang/reflect/Constructor.java =================================================================== RCS file: /sources/classpath/classpath/java/lang/reflect/Constructor.java,v retrieving revision 1.9 diff -u -u -r1.9 Constructor.java --- java/lang/reflect/Constructor.java 6 Mar 2008 20:22:19 -0000 1.9 +++ java/lang/reflect/Constructor.java 23 Jun 2008 20:42:37 -0000 @@ -106,10 +106,12 @@ * Gets the class that declared this constructor. * @return the class that declared this member */ - @SuppressWarnings("unchecked") public Class<T> getDeclaringClass() { - return (Class<T>) cons.getDeclaringClass(); + // Inescapable as the VM layer is 1.4 based. + @SuppressWarnings("unchecked") + Class<T> declClass = (Class<T>) cons.getDeclaringClass(); + return declClass; } /** @@ -162,7 +164,6 @@ * * @return a list of the types of the constructor's parameters */ - @SuppressWarnings("unchecked") public Class<?>[] getParameterTypes() { return (Class<?>[]) cons.getParameterTypes(); @@ -175,7 +176,6 @@ * * @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 @@ * @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 @@ * <code>null</code> if no such annotation exists. * @throws NullPointerException if the annotation class is <code>null</code>. */ - @SuppressWarnings("unchecked") public <T extends Annotation> T getAnnotation(Class<T> 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; } /** Index: java/lang/reflect/Field.java =================================================================== RCS file: /sources/classpath/classpath/java/lang/reflect/Field.java,v retrieving revision 1.9 diff -u -u -r1.9 Field.java --- java/lang/reflect/Field.java 6 Mar 2008 20:22:19 -0000 1.9 +++ java/lang/reflect/Field.java 23 Jun 2008 20:42:38 -0000 @@ -104,7 +104,6 @@ * 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 @@ * <code>null</code> if no such annotation exists. * @throws NullPointerException if the annotation class is <code>null</code>. */ - @SuppressWarnings("unchecked") public <T extends Annotation> T getAnnotation(Class<T> 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; } /** Index: java/lang/reflect/Method.java =================================================================== RCS file: /sources/classpath/classpath/java/lang/reflect/Method.java,v retrieving revision 1.8 diff -u -u -r1.8 Method.java --- java/lang/reflect/Method.java 6 Mar 2008 20:22:19 -0000 1.8 +++ java/lang/reflect/Method.java 23 Jun 2008 20:42:38 -0000 @@ -104,7 +104,6 @@ * 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 @@ * 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 @@ * * @return a list of the types of the method's parameters */ - @SuppressWarnings("unchecked") public Class<?>[] getParameterTypes() { return (Class<?>[]) m.getParameterTypes(); @@ -192,7 +189,6 @@ * * @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 @@ * <code>null</code> if no such annotation exists. * @throws NullPointerException if the annotation class is <code>null</code>. */ - @SuppressWarnings("unchecked") public <T extends Annotation> T getAnnotation(Class<T> 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; } /**