From: <zy...@us...> - 2009-05-11 02:39:20
|
Revision: 6335 http://jython.svn.sourceforge.net/jython/?rev=6335&view=rev Author: zyasoft Date: 2009-05-11 02:39:06 +0000 (Mon, 11 May 2009) Log Message: ----------- Applied fixes to problems found by findbugs. Modified Paths: -------------- trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyBytecode.java trunk/jython/src/org/python/core/PyInstance.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/PyUnicode.java trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java trunk/jython/src/org/python/core/packagecache/PathPackageManager.java trunk/jython/src/org/python/modules/cStringIO.java trunk/jython/src/org/python/modules/time/Time.java trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2009-05-11 00:49:23 UTC (rev 6334) +++ trunk/jython/src/org/python/core/Py.java 2009-05-11 02:39:06 UTC (rev 6335) @@ -490,15 +490,15 @@ /* Helper functions for PyProxy's */ /* Convenience methods to create new constants without using "new" */ - private static PyInteger[] integerCache = null; + private final static PyInteger[] integerCache = new PyInteger[1000]; + static { + for (int j = -100; j < 900; j++) { + integerCache[j + 100] = new PyInteger(j); + } + } + public static final PyInteger newInteger(int i) { - if (integerCache == null) { - integerCache = new PyInteger[1000]; - for (int j = -100; j < 900; j++) { - integerCache[j + 100] = new PyInteger(j); - } - } if (i >= -100 && i < 900) { return integerCache[i + 100]; } else { @@ -1442,8 +1442,15 @@ throw Py.TypeError("None required for void return"); } } - private static PyString[] letters = null; + + private final static PyString[] letters = new PyString[256]; + static { + for (char j = 0; j < 256; j++) { + letters[j] = new PyString(new Character(j).toString()); + } + } + public static final PyString makeCharacter(Character o) { return makeCharacter(o.charValue()); } @@ -1461,13 +1468,6 @@ } else if (codepoint > 256) { return new PyString((char)codepoint); } - - if (letters == null) { - letters = new PyString[256]; - for (char j = 0; j < 256; j++) { - letters[j] = new PyString(new Character(j).toString()); - } - } return letters[codepoint]; } Modified: trunk/jython/src/org/python/core/PyBytecode.java =================================================================== --- trunk/jython/src/org/python/core/PyBytecode.java 2009-05-11 00:49:23 UTC (rev 6334) +++ trunk/jython/src/org/python/core/PyBytecode.java 2009-05-11 02:39:06 UTC (rev 6335) @@ -175,7 +175,7 @@ }; // to enable why's to be stored on a PyStack - private class PyStackWhy extends PyObject { + private static class PyStackWhy extends PyObject { Why why; @@ -189,7 +189,7 @@ } } - private class PyStackException extends PyObject { + private static class PyStackException extends PyObject { PyException exception; @@ -1361,7 +1361,7 @@ // XXX - perhaps add support for max stack size (presumably from co_stacksize) // and capacity hints - private class PyStack { + private static class PyStack { final List<PyObject> stack; @@ -1479,7 +1479,7 @@ } } - private class PyTryBlock extends PyObject { // purely to sit on top of the existing PyFrame in f_exits!!! + private static class PyTryBlock extends PyObject { // purely to sit on top of the existing PyFrame in f_exits!!! int b_type; /* what kind of block this is */ Modified: trunk/jython/src/org/python/core/PyInstance.java =================================================================== --- trunk/jython/src/org/python/core/PyInstance.java 2009-05-11 00:49:23 UTC (rev 6334) +++ trunk/jython/src/org/python/core/PyInstance.java 2009-05-11 02:39:06 UTC (rev 6335) @@ -123,7 +123,7 @@ if (args.length != 0) { init = instclass.lookup("__init__"); if (init != null) { - ret = init.__call__(this, args, keywords); + init.__call__(this, args, keywords); } else { throw Py.TypeError("this constructor takes no arguments"); } Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-05-11 00:49:23 UTC (rev 6334) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-05-11 02:39:06 UTC (rev 6335) @@ -890,9 +890,6 @@ @Override public void setSlice(int start, int stop, int step, PyObject value) { - if (stop < start) { - stop = start; - } if (step == 0) { return; } Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-05-11 00:49:23 UTC (rev 6334) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-05-11 02:39:06 UTC (rev 6335) @@ -13,6 +13,7 @@ import java.nio.charset.UnsupportedCharsetException; import java.security.AccessControlException; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.StringTokenizer; import java.util.jar.JarEntry; @@ -650,9 +651,10 @@ FileInputStream fp = new FileInputStream(file); try { fileProperties.load(fp); - for (Object key : fileProperties.keySet()) { + for (Entry kv : fileProperties.entrySet()) { + Object key = kv.getKey(); if (!registry.containsKey(key)) { - registry.put(key, fileProperties.get(key)); + registry.put(key, kv.getValue()); } } } finally { Modified: trunk/jython/src/org/python/core/PyUnicode.java =================================================================== --- trunk/jython/src/org/python/core/PyUnicode.java 2009-05-11 00:49:23 UTC (rev 6334) +++ trunk/jython/src/org/python/core/PyUnicode.java 2009-05-11 02:39:06 UTC (rev 6335) @@ -365,7 +365,7 @@ } } - private class SteppedIterator<T> implements Iterator { + private static class SteppedIterator<T> implements Iterator { private final Iterator<T> iter; private final int step; @@ -526,7 +526,7 @@ return new PyUnicode(buffer); } - private class StripIterator implements Iterator { + private static class StripIterator implements Iterator { private final Iterator<Integer> iter; private int lookahead = -1; @@ -715,7 +715,7 @@ } } - private class PeekIterator<T> implements Iterator { + private static class PeekIterator<T> implements Iterator { private T lookahead = null; private final Iterator<T> iter; @@ -744,7 +744,7 @@ } } - private class ReversedIterator<T> implements Iterator { + private static class ReversedIterator<T> implements Iterator { private final List<T> reversed = Generic.list(); private final Iterator<T> iter; Modified: trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java =================================================================== --- trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java 2009-05-11 00:49:23 UTC (rev 6334) +++ trunk/jython/src/org/python/core/packagecache/CachedJarsPackageManager.java 2009-05-11 02:39:06 UTC (rev 6335) @@ -167,13 +167,13 @@ // Turn each vector into a comma-separated String Map<String, String> transformed = Generic.map(); - for (String key : zipPackages.keySet()) { - List<String>[] vec = zipPackages.get(key); + for (Entry<String,List<String>[]> kv : zipPackages.entrySet()) { + List<String>[] vec = kv.getValue(); String classes = listToString(vec[0]); if (vec[1].size() > 0) { classes += '@' + listToString(vec[1]); } - transformed.put(key, classes); + transformed.put(kv.getKey(), classes); } return transformed; @@ -344,6 +344,7 @@ // Read in cache file storing package info for a single .jar // Return null and delete this cachefile if it is invalid + @SuppressWarnings("empty-statement") private Map<String, String> readCacheFile(JarXEntry entry, String jarcanon) { String cachefile = entry.cachefile; long mtime = entry.mtime; @@ -388,9 +389,9 @@ ostream.writeLong(entry.mtime); comment("rewriting cachefile for '" + jarcanon + "'"); - for (String packageName : zipPackages.keySet()) { - String classes = zipPackages.get(packageName); - ostream.writeUTF(packageName); + for (Entry<String,String> kv : zipPackages.entrySet()) { + String classes = kv.getValue(); + ostream.writeUTF(kv.getKey()); ostream.writeUTF(classes); } ostream.close(); Modified: trunk/jython/src/org/python/core/packagecache/PathPackageManager.java =================================================================== --- trunk/jython/src/org/python/core/packagecache/PathPackageManager.java 2009-05-11 00:49:23 UTC (rev 6334) +++ trunk/jython/src/org/python/core/packagecache/PathPackageManager.java 2009-05-11 02:39:06 UTC (rev 6335) @@ -64,7 +64,7 @@ return false; } - class PackageExistsFileFilter implements FilenameFilter { + private static class PackageExistsFileFilter implements FilenameFilter { private boolean java; private boolean python; Modified: trunk/jython/src/org/python/modules/cStringIO.java =================================================================== --- trunk/jython/src/org/python/modules/cStringIO.java 2009-05-11 00:49:23 UTC (rev 6334) +++ trunk/jython/src/org/python/modules/cStringIO.java 2009-05-11 02:39:06 UTC (rev 6335) @@ -33,7 +33,7 @@ // would be nicer if we directly imported from os, but crazy to do so // since in python code itself - private class os { + private static class os { public static final int SEEK_SET = 0; public static final int SEEK_CUR = 1; public static final int SEEK_END = 2; Modified: trunk/jython/src/org/python/modules/time/Time.java =================================================================== --- trunk/jython/src/org/python/modules/time/Time.java 2009-05-11 00:49:23 UTC (rev 6334) +++ trunk/jython/src/org/python/modules/time/Time.java 2009-05-11 02:39:06 UTC (rev 6335) @@ -344,40 +344,40 @@ "Nov", "Dec"}; - private static String _shortday(int dow) { + private synchronized static String _shortday(int dow) { // we need to hand craft shortdays[] because Java and Python have // different specifications. Java (undocumented) appears to be // first element "", followed by 0=Sun. Python says 0=Mon - try { - if (shortdays == null) { - shortdays = new String[7]; - String[] names = datesyms.getShortWeekdays(); - for (int i=0; i<6; i++) - shortdays[i] = names[i+2]; - shortdays[6] = names[1]; + if (shortdays == null) { + shortdays = new String[7]; + String[] names = datesyms.getShortWeekdays(); + for (int i = 0; i < 6; i++) { + shortdays[i] = names[i + 2]; } + shortdays[6] = names[1]; } - catch (ArrayIndexOutOfBoundsException e) { - throwValueError("day of week out of range (0-6)"); + try { + return shortdays[dow]; + } catch (ArrayIndexOutOfBoundsException e) { + throw new PyException(Py.ValueError, new PyString("day of week out of range (0-6)")); } - return shortdays[dow]; } - private static String _shortmonth(int month0to11) { + private synchronized static String _shortmonth(int month0to11) { // getShortWeekdays() returns a 13 element array with the last item // being the empty string. This is also undocumented ;-/ - try { - if (shortmonths == null) { - shortmonths = new String[12]; - String[] names = datesyms.getShortMonths(); - for (int i=0; i<12; i++) - shortmonths[i] = names[i]; + if (shortmonths == null) { + shortmonths = new String[12]; + String[] names = datesyms.getShortMonths(); + for (int i = 0; i < 12; i++) { + shortmonths[i] = names[i]; } } - catch (ArrayIndexOutOfBoundsException e) { - throwValueError("month out of range (1-12)"); + try { + return shortmonths[month0to11]; + } catch (ArrayIndexOutOfBoundsException e) { + throw new PyException(Py.ValueError, new PyString("month out of range (1-12)")); } - return shortmonths[month0to11]; } private static String _padint(int i, int target) { Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-05-11 00:49:23 UTC (rev 6334) +++ trunk/jython/src/org/python/util/jython.java 2009-05-11 02:39:06 UTC (rev 6335) @@ -220,12 +220,16 @@ } catch (FileNotFoundException e) { throw Py.IOError(e); } - if (FileUtil.isatty(file.getFD())) { - opts.interactive = true; - interp.interact(null, new PyFile(file)); - System.exit(0); - } else { - interp.execfile(file, opts.filename); + try { + if (FileUtil.isatty(file.getFD())) { + opts.interactive = true; + interp.interact(null, new PyFile(file)); + System.exit(0); + } else { + interp.execfile(file, opts.filename); + } + } finally { + file.close(); } } catch (Throwable t) { if (t instanceof PyException This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |