From: <otm...@us...> - 2009-04-20 17:48:00
|
Revision: 6247 http://jython.svn.sourceforge.net/jython/?rev=6247&view=rev Author: otmarhumbel Date: 2009-04-20 17:47:43 +0000 (Mon, 20 Apr 2009) Log Message: ----------- throw a meaningful exception instead of a NullPointerException if version.properties cannot be loaded Modified Paths: -------------- trunk/jython/src/org/python/Version.java Modified: trunk/jython/src/org/python/Version.java =================================================================== --- trunk/jython/src/org/python/Version.java 2009-04-19 20:59:54 UTC (rev 6246) +++ trunk/jython/src/org/python/Version.java 2009-04-20 17:47:43 UTC (rev 6247) @@ -1,8 +1,8 @@ /* Copyright (c) Jython Developers */ package org.python; +import java.io.IOException; import java.io.InputStream; -import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.EnumSet; @@ -86,31 +86,39 @@ * Load the version information from the properties file. */ private static void loadProperties() { - InputStream in = Version.class.getResourceAsStream("/org/python/version.properties"); - Properties properties = new Properties(); - try { - properties.load(in); - } catch (IOException ioe) { - System.err.println("There was a problem loading version.properties:"); - ioe.printStackTrace(); - } finally { + boolean loaded = false; + final String versionProperties = "/org/python/version.properties"; + InputStream in = Version.class.getResourceAsStream(versionProperties); + if (in != null) { try { - in.close(); + Properties properties = new Properties(); + properties.load(in); + loaded = true; + PY_VERSION = properties.getProperty("jython.version"); + PY_MAJOR_VERSION = Integer.valueOf(properties.getProperty("jython.major_version")); + PY_MINOR_VERSION = Integer.valueOf(properties.getProperty("jython.minor_version")); + PY_MICRO_VERSION = Integer.valueOf(properties.getProperty("jython.micro_version")); + PY_RELEASE_LEVEL = Integer.valueOf(properties.getProperty("jython.release_level")); + PY_RELEASE_SERIAL = Integer.valueOf(properties.getProperty("jython.release_serial")); + DATE = properties.getProperty("jython.build.date"); + TIME = properties.getProperty("jython.build.time"); + SVN_REVISION = properties.getProperty("jython.build.svn_revision"); } catch (IOException ioe) { - // ok + System.err.println("There was a problem loading ".concat(versionProperties) + .concat(":")); + ioe.printStackTrace(); + } finally { + try { + in.close(); + } catch (IOException ioe) { + // ok + } } } - - PY_VERSION = properties.getProperty("jython.version"); - PY_MAJOR_VERSION = Integer.valueOf(properties.getProperty("jython.major_version")); - PY_MINOR_VERSION = Integer.valueOf(properties.getProperty("jython.minor_version")); - PY_MICRO_VERSION = Integer.valueOf(properties.getProperty("jython.micro_version")); - PY_RELEASE_LEVEL = Integer.valueOf(properties.getProperty("jython.release_level")); - PY_RELEASE_SERIAL = Integer.valueOf(properties.getProperty("jython.release_serial")); - - DATE = properties.getProperty("jython.build.date"); - TIME = properties.getProperty("jython.build.time"); - SVN_REVISION = properties.getProperty("jython.build.svn_revision"); + if (!loaded) { + // fail with a meaningful exception (cannot use Py exceptions here) + throw new RuntimeException("unable to load ".concat(versionProperties)); + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |