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/24 15:04:50 UTC

svn commit: r1792480 - /pivot/branches/2.0.x/core/src/org/apache/pivot/util/Version.java

Author: rwhitcomb
Date: Mon Apr 24 15:04:50 2017
New Revision: 1792480

URL: http://svn.apache.org/viewvc?rev=1792480&view=rev
Log:
PIVOT-993:  Update Version.java to work with Oracle JDK 8u131.

Problem related to trying to parse the "131" value into a byte
which results in overflow.

Take patch proposed by Todd Volkert and widen all the fields
in Version to "short", and the "getNumber()" result to a long
to account for the wider fields.


Modified:
    pivot/branches/2.0.x/core/src/org/apache/pivot/util/Version.java

Modified: pivot/branches/2.0.x/core/src/org/apache/pivot/util/Version.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/core/src/org/apache/pivot/util/Version.java?rev=1792480&r1=1792479&r2=1792480&view=diff
==============================================================================
--- pivot/branches/2.0.x/core/src/org/apache/pivot/util/Version.java (original)
+++ pivot/branches/2.0.x/core/src/org/apache/pivot/util/Version.java Mon Apr 24 15:04:50 2017
@@ -28,10 +28,10 @@ import java.io.Serializable;
 public class Version implements Comparable<Version>, Serializable {
     private static final long serialVersionUID = -3677773163272115116L;
 
-    private byte majorRevision = 0;
-    private byte minorRevision = 0;
-    private byte maintenanceRevision = 0;
-    private byte updateRevision = 0;
+    private short majorRevision = 0;
+    private short minorRevision = 0;
+    private short maintenanceRevision = 0;
+    private short updateRevision = 0;
     private String build = null;
 
     public Version(int majorRevision, int minorRevision, int maintenanceRevision,
@@ -41,61 +41,61 @@ public class Version implements Comparab
 
     public Version(int majorRevision, int minorRevision, int maintenanceRevision,
         int updateRevision, String build) {
-        if (majorRevision > 0x7f) {
+        if (majorRevision > 0x7fff) {
             throw new IllegalArgumentException("majorRevision must be less than "
-                + 0x7f + ".");
+                + 0x7fff + ".");
         }
 
-        if (minorRevision > 0xff) {
+        if (minorRevision > 0x7fff) {
             throw new IllegalArgumentException("minorRevision must be less than "
-                + 0xff + ".");
+                + 0x7fff + ".");
         }
 
-        if (maintenanceRevision > 0xff) {
+        if (maintenanceRevision > 0x7fff) {
             throw new IllegalArgumentException("maintenanceRevision must be less than "
-                + 0xff + ".");
+                + 0x7fff + ".");
         }
 
-        if (updateRevision > 0xff) {
+        if (updateRevision > 0x7fff) {
             throw new IllegalArgumentException("updateRevision must be less than "
-                + 0xff + ".");
+                + 0x7fff + ".");
         }
 
-        this.majorRevision = (byte)majorRevision;
-        this.minorRevision = (byte)minorRevision;
-        this.maintenanceRevision = (byte)maintenanceRevision;
-        this.updateRevision = (byte)updateRevision;
+        this.majorRevision = (short)majorRevision;
+        this.minorRevision = (short)minorRevision;
+        this.maintenanceRevision = (short)maintenanceRevision;
+        this.updateRevision = (short)updateRevision;
         this.build = build;
     }
 
-    public byte getMajorRevision() {
-        return this.majorRevision;
+    public short getMajorRevision() {
+        return majorRevision;
     }
 
-    public byte getMinorRevision() {
-        return this.minorRevision;
+    public short getMinorRevision() {
+        return minorRevision;
     }
 
-    public byte getMaintenanceRevision() {
-        return this.maintenanceRevision;
+    public short getMaintenanceRevision() {
+        return maintenanceRevision;
     }
 
-    public byte getUpdateRevision() {
-        return this.updateRevision;
+    public short getUpdateRevision() {
+        return updateRevision;
     }
 
-    public int getNumber() {
-        int number = ((this.majorRevision) & 0xff) << (8 * 3)
-            | ((this.minorRevision) & 0xff) << (8 * 2)
-            | ((this.maintenanceRevision) & 0xff) << (8 * 1)
-            | ((this.updateRevision) & 0xff) << (8 * 0);
+    public long getNumber() {
+        long number = ((majorRevision) & 0xffff) << (16 * 3)
+            | ((minorRevision) & 0xffff) << (16 * 2)
+            | ((maintenanceRevision) & 0xffff) << (16 * 1)
+            | ((updateRevision) & 0xffff) << (16 * 0);
 
         return number;
     }
 
     @Override
     public int compareTo(Version version) {
-        return (getNumber() - version.getNumber());
+        return new Long(getNumber()).compareTo(version.getNumber());
     }
 
     @Override
@@ -106,7 +106,7 @@ public class Version implements Comparab
 
     @Override
     public int hashCode() {
-        return getNumber();
+        return new Long(getNumber()).hashCode();
     }
 
     @Override
@@ -126,10 +126,10 @@ public class Version implements Comparab
     public static Version decode(String string) {
         Version version = null;
 
-        byte majorRevision = 0;
-        byte minorRevision = 0;
-        byte maintenanceRevision = 0;
-        byte updateRevision = 0;
+        short majorRevision = 0;
+        short minorRevision = 0;
+        short maintenanceRevision = 0;
+        short updateRevision = 0;
         String build = null;
 
         String revision;
@@ -144,19 +144,19 @@ public class Version implements Comparab
         String[] revisionNumbers = revision.split("\\.");
 
         if (revisionNumbers.length > 0) {
-            majorRevision = Byte.parseByte(revisionNumbers[0]);
+            majorRevision = Short.parseShort(revisionNumbers[0]);
 
             if (revisionNumbers.length > 1) {
-                minorRevision = Byte.parseByte(revisionNumbers[1]);
+                minorRevision = Short.parseShort(revisionNumbers[1]);
 
                 if (revisionNumbers.length > 2) {
                     String[] maintenanceRevisionNumbers = revisionNumbers[2].split("_");
 
                     if (maintenanceRevisionNumbers.length > 0) {
-                        maintenanceRevision = Byte.parseByte(maintenanceRevisionNumbers[0]);
+                        maintenanceRevision = Short.parseShort(maintenanceRevisionNumbers[0]);
 
                         if (maintenanceRevisionNumbers.length > 1) {
-                            updateRevision = Byte.parseByte(maintenanceRevisionNumbers[1]);
+                            updateRevision = Short.parseShort(maintenanceRevisionNumbers[1]);
                         }
                     }
                 }