From 6facd3d12faf76fc757cf15e313b236d01d6ba51 Mon Sep 17 00:00:00 2001 From: samskivert Date: Sun, 7 Mar 2010 18:10:10 +0000 Subject: [PATCH] 1.7 javac is apparently more perceptive than ejc when it comes to warning about raw type usage. I'm surprised that the Eclipse code hygienist failed to catch these. Also had to be slightly more blatant in a few places where we're subverting the generics type system because the 1.7 javac is less tolerant of the fast and loose. For future reference, that usually means first assigning a reference to a wildcard and then casting that to what you want: Foo fc = someFooWithCrazyAssParameters; @SuppressWarnings("unchecked") Foo fo = (Foo)fc; instead of just: @SuppressWarnings("unchecked") Foo fo = (Foo)someFooWithCrazyAssParameters; because javac won't let you do casts that are inconvertible and it's smarter about what sort of generic types are convertible to one another. Hopefully this future reference won't be needed because we won't be needing to subvert the type system. But when reflection is involved, it's hard not to end up doing a bit of the old Father Knows Best. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2756 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/jdbc/jora/Table.java | 4 ++-- src/java/com/samskivert/swing/TableSorter.java | 7 ++++--- .../com/samskivert/swing/util/TaskMaster.java | 2 +- src/java/com/samskivert/util/ClassUtil.java | 2 +- src/java/com/samskivert/util/Comparators.java | 18 ++++++++++-------- src/java/com/samskivert/util/CountHashMap.java | 5 +++-- src/java/com/samskivert/util/HashIntMap.java | 2 +- src/java/com/samskivert/util/MethodFinder.java | 4 ++-- src/java/com/samskivert/util/StringUtil.java | 2 +- .../samskivert/velocity/DispatcherServlet.java | 1 + 10 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/java/com/samskivert/jdbc/jora/Table.java b/src/java/com/samskivert/jdbc/jora/Table.java index d3d1b594..9053122b 100644 --- a/src/java/com/samskivert/jdbc/jora/Table.java +++ b/src/java/com/samskivert/jdbc/jora/Table.java @@ -448,7 +448,7 @@ public class Table fMask = new FieldMask(fields); try { - constructor = _rowClass.getDeclaredConstructor(new Class[0]); + constructor = _rowClass.getDeclaredConstructor(new Class[0]); setBypass.invoke(constructor, bypassFlag); } catch(Exception ex) {} @@ -571,7 +571,7 @@ public class Table try { fd.constructor = - fieldClass.getDeclaredConstructor(new Class[0]); + fieldClass.getDeclaredConstructor(new Class[0]); setBypass.invoke(fd.constructor, bypassFlag); } catch(Exception ex) {} diff --git a/src/java/com/samskivert/swing/TableSorter.java b/src/java/com/samskivert/swing/TableSorter.java index 931cae52..076504fb 100644 --- a/src/java/com/samskivert/swing/TableSorter.java +++ b/src/java/com/samskivert/swing/TableSorter.java @@ -236,9 +236,10 @@ public class TableSorter extends AbstractTableModel { return comparator; } if (Comparable.class.isAssignableFrom(columnType)) { - @SuppressWarnings("unchecked") - Comparator c = Comparators.COMPARABLE; - return c; + // this is messy, but reflection and generics don't play nice + Comparator c = Comparators.COMPARABLE; + @SuppressWarnings("unchecked") Comparator co = (Comparator)c; + return co; } return Comparators.LEXICAL_CASE_INSENSITIVE; } diff --git a/src/java/com/samskivert/swing/util/TaskMaster.java b/src/java/com/samskivert/swing/util/TaskMaster.java index 9772f0e7..8f8dbfff 100644 --- a/src/java/com/samskivert/swing/util/TaskMaster.java +++ b/src/java/com/samskivert/swing/util/TaskMaster.java @@ -169,7 +169,7 @@ public class TaskMaster public Object invoke () throws Exception { // look up the named method on the source object and invoke it - Method meth = _source.getClass().getMethod(_name, (Class[]) null); + Method meth = _source.getClass().getMethod(_name, (Class[]) null); meth.setAccessible(true); return meth.invoke(_source, (Object[]) null); } diff --git a/src/java/com/samskivert/util/ClassUtil.java b/src/java/com/samskivert/util/ClassUtil.java index a00b36dd..6d898c80 100644 --- a/src/java/com/samskivert/util/ClassUtil.java +++ b/src/java/com/samskivert/util/ClassUtil.java @@ -104,7 +104,7 @@ public class ClassUtil { Class[] argTypes = null; if (args != null) { - argTypes = new Class[args.length]; + argTypes = new Class[args.length]; for (int i = 0; i < args.length; ++i) { argTypes[i] = (args[i] == null) ? Void.TYPE : args[i].getClass(); } diff --git a/src/java/com/samskivert/util/Comparators.java b/src/java/com/samskivert/util/Comparators.java index 624e1583..3caef8cf 100644 --- a/src/java/com/samskivert/util/Comparators.java +++ b/src/java/com/samskivert/util/Comparators.java @@ -47,11 +47,11 @@ public class Comparators }; /** - * A comparator that compares {@link Comparable} instances. + * A comparator that compares {@link Comparable} instances. */ - @SuppressWarnings("unchecked") - public static final Comparator COMPARABLE = new Comparator() { - public int compare (Object o1, Object o2) + public static final Comparator> COMPARABLE = + new Comparator>() { + public int compare (Comparable o1, Comparable o2) { if (o1 == o2) { // catches null == null return 0; @@ -60,7 +60,7 @@ public class Comparators } else if (o2 == null) { return -1; } - return ((Comparable)o1).compareTo(o2); // null-free + return o1.compareTo(o2); // null-free } }; @@ -72,10 +72,12 @@ public class Comparators * Comparator<Integer> = Comparators.comparable(); * */ - @SuppressWarnings("unchecked") - public static final Comparator comparable () + // we can't do the "more correct" > here as that causes other + // code to freak out; I don't entirely understand why + public static final > Comparator comparable () { - return COMPARABLE; + @SuppressWarnings("unchecked") Comparator comp = (Comparator)COMPARABLE; + return comp; } /** diff --git a/src/java/com/samskivert/util/CountHashMap.java b/src/java/com/samskivert/util/CountHashMap.java index fb4cb210..db3199b9 100644 --- a/src/java/com/samskivert/util/CountHashMap.java +++ b/src/java/com/samskivert/util/CountHashMap.java @@ -125,12 +125,13 @@ public class CountHashMap extends HashMap } @Override - @SuppressWarnings("unchecked") public Set> entrySet () { // a giant mess of hoop-jumpery so that we can convert each Map.Entry returned by the // iterator to be a CountEntryImpl - return new CountEntrySet(super.entrySet()); + Set eset = new CountEntrySet(super.entrySet()); + @SuppressWarnings("unchecked") Set> r = (Set>)eset; + return r; } /** diff --git a/src/java/com/samskivert/util/HashIntMap.java b/src/java/com/samskivert/util/HashIntMap.java index c685c99b..cae9f288 100644 --- a/src/java/com/samskivert/util/HashIntMap.java +++ b/src/java/com/samskivert/util/HashIntMap.java @@ -517,7 +517,7 @@ public class HashIntMap extends AbstractMap protected Record[] createBuckets (int size) { - @SuppressWarnings("unchecked") Record[] recs = new Record[size]; + @SuppressWarnings("unchecked") Record[] recs = (Record[])new Record[size]; return recs; } diff --git a/src/java/com/samskivert/util/MethodFinder.java b/src/java/com/samskivert/util/MethodFinder.java index 84c86103..d9d0fb67 100644 --- a/src/java/com/samskivert/util/MethodFinder.java +++ b/src/java/com/samskivert/util/MethodFinder.java @@ -99,7 +99,7 @@ public class MethodFinder maybeLoadConstructors(); if (parameterTypes == null) { - parameterTypes = new Class[0]; + parameterTypes = new Class[0]; } return (Constructor)findMemberIn(_ctorList, parameterTypes); @@ -135,7 +135,7 @@ public class MethodFinder } if (parameterTypes == null) { - parameterTypes = new Class[0]; + parameterTypes = new Class[0]; } return (Method)findMemberIn(methodList, parameterTypes); diff --git a/src/java/com/samskivert/util/StringUtil.java b/src/java/com/samskivert/util/StringUtil.java index 4e885b35..34f4ca34 100644 --- a/src/java/com/samskivert/util/StringUtil.java +++ b/src/java/com/samskivert/util/StringUtil.java @@ -707,7 +707,7 @@ public class StringUtil buf.append(fields[i].getName()).append("="); try { try { - Method meth = clazz.getMethod(fields[i].getName() + "ToString", new Class[0]); + Method meth = clazz.getMethod(fields[i].getName() + "ToString", new Class[0]); buf.append(meth.invoke(object, (Object[]) null)); } catch (NoSuchMethodException nsme) { toString(buf, fields[i].get(object)); diff --git a/src/java/com/samskivert/velocity/DispatcherServlet.java b/src/java/com/samskivert/velocity/DispatcherServlet.java index feea627b..1f85322c 100644 --- a/src/java/com/samskivert/velocity/DispatcherServlet.java +++ b/src/java/com/samskivert/velocity/DispatcherServlet.java @@ -418,6 +418,7 @@ public class DispatcherServlet extends HttpServlet /** * Called when a method throws an exception during template evaluation. */ + @Override @SuppressWarnings("rawtypes") // our super class declares a bare Class public Object methodException (Class clazz, String method, Exception e) throws Exception {