changeset 1572:6b95c888541f

2009-05-29 Omair Majid <omajid@redhat.com> * rt/net/sourceforge/jnlp/JREDesc.java: Change initialHeapSize and maximumHeapSize to String. (JREDesc): Check and store initialHeapSize and maximumHeapSize. Throw ParseException on error. (getMaximumHeapSize): Return String. (getInitialHeapSize): Likewise. (heapToLong): Renamed to... (checkHeapSize): New method. Check for valid heap size. * rt/net/sourceforge/jnlp/resources/Messages.properties: Add PBadHeapSize to indicate a bad heap size.
author Omair Majid <omajid@redhat.com>
date Fri, 29 May 2009 12:13:53 -0400
parents e3339b19c3d9
children b7825ac40fd9
files ChangeLog rt/net/sourceforge/jnlp/JREDesc.java rt/net/sourceforge/jnlp/resources/Messages.properties
diffstat 3 files changed, 55 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri May 29 12:38:51 2009 +0100
+++ b/ChangeLog	Fri May 29 12:13:53 2009 -0400
@@ -1,3 +1,16 @@
+2009-05-29  Omair Majid  <omajid@redhat.com>
+
+	* rt/net/sourceforge/jnlp/JREDesc.java:
+	Change initialHeapSize and maximumHeapSize to String.
+	(JREDesc): Check and store initialHeapSize and maximumHeapSize. Throw
+	ParseException on error.
+	(getMaximumHeapSize): Return String.
+	(getInitialHeapSize): Likewise.
+	(heapToLong): Renamed to...
+	(checkHeapSize): New method. Check for valid heap size.
+	* rt/net/sourceforge/jnlp/resources/Messages.properties: Add PBadHeapSize
+	to indicate a bad heap size.
+
 2009-05-29  Gary Benson  <gbenson@redhat.com>
 
 	* ports/hotspot/src/share/vm/shark/sharkBlock.hpp
--- a/rt/net/sourceforge/jnlp/JREDesc.java	Fri May 29 12:38:51 2009 +0100
+++ b/rt/net/sourceforge/jnlp/JREDesc.java	Fri May 29 12:13:53 2009 -0400
@@ -21,6 +21,8 @@
 import java.net.*;
 import java.util.*;
 
+import net.sourceforge.jnlp.runtime.JNLPRuntime;
+
 /**
  * The J2SE/Java element.
  *
@@ -36,10 +38,10 @@
     private URL location;
 
     /** inital heap size */
-    private long initialHeapSize;
+    private String initialHeapSize;
 
     /** maximum head size */
-    private long maximumHeapSize;
+    private String maximumHeapSize;
 
     /** args to pass to the vm */
     private String vmArgs;
@@ -60,12 +62,14 @@
      */
     public JREDesc(Version version, URL location, 
             String vmArgs, String initialHeapSize, 
-            String maximumHeapSize, List resources) {
+            String maximumHeapSize, List resources) throws ParseException {
         this.version = version;
         this.location = location;
         this.vmArgs = vmArgs;
-        this.initialHeapSize = heapToLong(initialHeapSize);
-        this.maximumHeapSize = heapToLong(maximumHeapSize);
+        checkHeapSize(initialHeapSize);
+        this.initialHeapSize = initialHeapSize;
+        checkHeapSize(maximumHeapSize);
+        this.maximumHeapSize = maximumHeapSize;
         this.resources = resources;
     }
 
@@ -97,14 +101,14 @@
     /**
      * Returns the maximum heap size in bytes.
      */
-    public long getMaximumHeapSize() {
+    public String getMaximumHeapSize() {
         return maximumHeapSize;
     }
 
     /**
      * Returns the initial heap size in bytes.
      */
-    public long getInitialHeapSize() {
+    public String getInitialHeapSize() {
         return initialHeapSize;
     }
 
@@ -123,12 +127,38 @@
     }
     
     /**
-     * Convert a heap size description string to a long value
-     * indicating the heap min/max size.
+     * Check for valid heap size string
+     * @throws ParseException if heapSize is invalid
      */
-    static private long heapToLong(String heapSize) {
+    static private void checkHeapSize(String heapSize) throws ParseException {
         // need to implement for completeness even though not used in netx
-        return -1;
+        if (heapSize == null) {
+            return;
+        }
+        
+        boolean lastCharacterIsDigit = true;
+        // the last character must be 0-9 or k/K/m/M
+        char lastChar = Character.toLowerCase(heapSize.charAt(heapSize.length()-1));
+        if ((lastChar < '0' || lastChar > '9')) {
+            lastCharacterIsDigit = false;
+            if (lastChar != 'k' && lastChar!= 'm' ) {
+                throw new ParseException(JNLPRuntime.getMessage("PBadHeapSize",new Object[] {heapSize}));
+            }
+        }
+        
+        int indexOfLastDigit = heapSize.length() - 1;
+        if (!lastCharacterIsDigit) {
+            indexOfLastDigit = indexOfLastDigit - 1;
+        }
+        
+        String size = heapSize.substring(0,indexOfLastDigit);
+        try {
+            // check that the number is a number!
+            Integer.valueOf(size);
+        } catch (NumberFormatException numberFormat) {
+            throw new ParseException(JNLPRuntime.getMessage("PBadHeapSize", new Object[] {heapSize}), numberFormat);
+        }
+              
     }
 
 }
--- a/rt/net/sourceforge/jnlp/resources/Messages.properties	Fri May 29 12:38:51 2009 +0100
+++ b/rt/net/sourceforge/jnlp/resources/Messages.properties	Fri May 29 12:13:53 2009 -0400
@@ -88,6 +88,7 @@
 PBadNonrelativeUrl=Invalid non-relative URL (node={0}, href={0}).
 PNeedsAttribute=The {0} element must specify a {1} attribute.
 PBadXML=Invalid XML document syntax.
+PBadHeapSize=Invalid value for heap size ({0})
 
 # Runtime
 BLaunchAbout=Launching about window...