You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2017/04/26 20:41:17 UTC

svn commit: r1792808 - in /pivot/branches/2.0.x: ./ wtk/src/org/apache/pivot/wtk/ApplicationContext.java

Author: rwhitcomb
Date: Wed Apr 26 20:41:17 2017
New Revision: 1792808

URL: http://svn.apache.org/viewvc?rev=1792808&view=rev
Log:
PIVOT-996:  Yet more safety measures:  Parse the version strings inside a new
"safelyDecodeVersion()" method that traps all exceptions and provides an
"empty" version (that is, "0.0.0_00") in case of any errors.  This is what
the Pivot version already did, so use the same technique for the JVM and Java
versions.

Change the Javadoc for the three accessor methods to note this change of
behavior in case of errors.

Note: This should make application startup possible no matter what might
happen to version strings in the future.  We don't want these types of
urgent issues to come up ever again, to where the user application won't
start just because of a JVM update/change.

This is a merge of revision 1792807 from "trunk" to "branches/2.0.x".

Modified:
    pivot/branches/2.0.x/   (props changed)
    pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java

Propchange: pivot/branches/2.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Apr 26 20:41:17 2017
@@ -1 +1 @@
-/pivot/trunk:1346574,1347051,1394847,1394858,1398511,1399331,1401781,1405882,1407585,1409081,1410536,1410555,1417081,1417258,1428056,1428650,1435351,1436707,1438126,1438659,1444260,1444910,1502657,1510821,1516518,1519859,1522078,1523205,1523736,1523776,1525982,1526005,1536829,1537222,1604238,1610563,1611829,1614462,1624381,1675204,1675517,1678238,1678251,1687873-1687874,1688306,1688484,1688523,1691618,1712175,1717360,1727931,1728247,1729480,1729493,1730100,1730108,1735181,1735282,1740570,1747445,1750549,1756534,1783447,1792531,1792556,1792559,1792775,1792793
+/pivot/trunk:1346574,1347051,1394847,1394858,1398511,1399331,1401781,1405882,1407585,1409081,1410536,1410555,1417081,1417258,1428056,1428650,1435351,1436707,1438126,1438659,1444260,1444910,1502657,1510821,1516518,1519859,1522078,1523205,1523736,1523776,1525982,1526005,1536829,1537222,1604238,1610563,1611829,1614462,1624381,1675204,1675517,1678238,1678251,1687873-1687874,1688306,1688484,1688523,1691618,1712175,1717360,1727931,1728247,1729480,1729493,1730100,1730108,1735181,1735282,1740570,1747445,1750549,1756534,1783447,1792531,1792556,1792559,1792775,1792793,1792807

Modified: pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java?rev=1792808&r1=1792807&r2=1792808&view=diff
==============================================================================
--- pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java (original)
+++ pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java Wed Apr 26 20:41:17 2017
@@ -1714,6 +1714,28 @@ public abstract class ApplicationContext
         }
     }
 
+    /**
+     * Added so that any unexpected version string formats that might cause an error
+     * will not also cause the application to fail to start.
+     *
+     * @param versionString A potential version string to parse/decode.
+     * @return The parsed version information (if possible), or an empty version
+     * (that will look like: "0.0.0_00") if there was a parsing problem of any kind.
+     */
+    private static Version safelyDecodeVersion(String versionString) {
+        if (versionString != null && !versionString.isEmpty()) {
+            try {
+                return Version.decode(versionString);
+            } catch (Throwable ex) {
+                String msg = ex.getMessage();
+                String exMsg = (msg == null || msg.isEmpty()) ? ex.getClass().getSimpleName() : msg;
+                System.err.println("Error decoding version string \"" + versionString + "\": " + exMsg);
+            }
+        }
+        return new Version(0, 0, 0, 0);
+    }
+
+
     protected static URL origin = null;
     protected static ArrayList<Display> displays = new ArrayList<Display>();
     protected static ArrayList<Application> applications = new ArrayList<Application>();
@@ -1728,17 +1750,12 @@ public abstract class ApplicationContext
     private static Version pivotVersion = null;
 
     static {
-        // Get the JVM version
-        jvmVersion = Version.decode(System.getProperty("java.vm.version"));
-        javaVersion = Version.decode(System.getProperty("java.runtime.version"));
+        // Get the JVM & Java runtime versions
+        jvmVersion = safelyDecodeVersion(System.getProperty("java.vm.version"));
+        javaVersion = safelyDecodeVersion(System.getProperty("java.runtime.version"));
 
         // Get the Pivot version
-        String version = ApplicationContext.class.getPackage().getImplementationVersion();
-        if (version == null) {
-            pivotVersion = new Version(0, 0, 0, 0);
-        } else {
-            pivotVersion = Version.decode(version);
-        }
+        pivotVersion = safelyDecodeVersion(ApplicationContext.class.getPackage().getImplementationVersion());
     }
 
     /**
@@ -1818,9 +1835,8 @@ public abstract class ApplicationContext
      * Returns the current JVM version, parsed from the "java.vm.version" system
      * property.
      *
-     * @return
-     * The current JVM version, or <tt>null</tt> if the version can't be
-     * determined.
+     * @return The current JVM version, or an "empty" version if it can't be
+     * determined (that is, "0.0.0_00").
      */
     public static Version getJVMVersion() {
         return jvmVersion;
@@ -1830,8 +1846,8 @@ public abstract class ApplicationContext
      * Returns the current Java Runtime version, parsed from the "java.runtime.version"
      * system property.
      *
-     * @return The current Java version, or <tt>null</tt> if the version can't be
-     * determined.
+     * @return The current Java version, or an "empty" version if it can't be
+     * determined (that is, "0.0.0_00").
      */
     public static Version getJavaVersion() {
         return javaVersion;
@@ -1840,9 +1856,8 @@ public abstract class ApplicationContext
     /**
      * Returns the current Pivot version.
      *
-     * @return
-     * The current Pivot version (determined at build time), or <tt>null</tt>
-     * if the version can't be determined.
+     * @return The current Pivot version (determined at build time), or
+     * an "empty" version if it can't be determined (that is, "0.0.0_00").
      */
     public static Version getPivotVersion() {
         return pivotVersion;