[kaffe] CVS kaffe (dalibor): small fix for argument checking in java.awt.BasicStroke

Kaffe CVS Kaffe Mailing List <kaffe@kaffe.org>
Wed Sep 3 06:38:02 2003


PatchSet 4015 
Date: 2003/09/03 13:34:59
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
small fix for argument checking in java.awt.BasicStroke

Needed for StatCVS to proceed a little bit further. It still can't generate such images like
http://www.kaffe.org/~robilad/loc.png on kaffe due to the lack of swing and an UnsupportedOperationException
java.lang.UnsupportedOperationException
   at java.awt.image.ColorModel.createCompatibleSampleModel (ColorModel.java:617)
   at java.awt.image.ColorModel.createCompatibleWritableRaster (ColorModel.java:610)
   at java.awt.image.BufferedImage.<init> (BufferedImage.java:199)
   at com.jrefinery.chart.JFreeChart.createBufferedImage (source file unknown)
   at com.jrefinery.chart.ChartUtilities.writeChartAsPNG (source file unknown)
   at com.jrefinery.chart.ChartUtilities.saveChartAsPNG (source file unknown)
   at com.jrefinery.chart.ChartUtilities.saveChartAsPNG (source file unknown)
   at net.sf.statcvs.renderer.ChartRenderer.saveChartAsPng (ChartRenderer.java:58)
   at net.sf.statcvs.renderer.LOCChart.<init> (LOCChart.java:70)
   at net.sf.statcvs.output.HTMLOutput.createLOCChart (HTMLOutput.java:112)
   at net.sf.statcvs.output.ModulePage.getLOC (ModulePage.java:143)
   at net.sf.statcvs.output.ModulePage.printBody (ModulePage.java:85)
   at net.sf.statcvs.output.HTMLPage.createPage (HTMLPage.java:67)
   at net.sf.statcvs.output.ModulePage.<init> (ModulePage.java:74)
   at net.sf.statcvs.output.IndexPage.getIndexTree (IndexPage.java:136)
   at net.sf.statcvs.output.IndexPage.printBody (IndexPage.java:78)
   at net.sf.statcvs.output.HTMLPage.createPage (HTMLPage.java:67)
   at net.sf.statcvs.output.IndexPage.<init> (IndexPage.java:58)
   at net.sf.statcvs.output.HTMLOutput.createHTMLSuite (HTMLOutput.java:65)
   at net.sf.statcvs.Main.generateDefaultHTMLSuite (Main.java:165)
   at net.sf.statcvs.Main.execute (Main.java:94)
   at net.sf.statcvs.Main.main (Main.java:74)
   at java.lang.reflect.Method.invoke0 (Method.java)
   at java.lang.reflect.Method.invoke (Method.java:255)
   at kaffe.jar.ExecJarName.main (ExecJarName.java:67)
   at kaffe.jar.ExecJar.main (ExecJar.java:75)
but it's getting at least this far with Sun's swing 1.1.1 jar.

Members: 
	ChangeLog:1.1611->1.1612 
	libraries/javalib/java/awt/BasicStroke.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1611 kaffe/ChangeLog:1.1612
--- kaffe/ChangeLog:1.1611	Tue Sep  2 23:38:27 2003
+++ kaffe/ChangeLog	Wed Sep  3 13:34:59 2003
@@ -1,3 +1,8 @@
+2003-09-03  Dalibor Topic <robilad@kaffe.org>
+
+	* libraries/javalib/java/awt/BasicStroke.java:
+	(BasicStroke) Fixed illegal argument checking to follow 1.4.2 spec.
+
 2003-09-02  Jim Pick  <jim@kaffe.org>
 
 	* libraries/clib/net/PlainDatagramSocketImpl.c:
Index: kaffe/libraries/javalib/java/awt/BasicStroke.java
diff -u kaffe/libraries/javalib/java/awt/BasicStroke.java:1.2 kaffe/libraries/javalib/java/awt/BasicStroke.java:1.3
--- kaffe/libraries/javalib/java/awt/BasicStroke.java:1.2	Sun Jan 12 19:56:22 2003
+++ kaffe/libraries/javalib/java/awt/BasicStroke.java	Wed Sep  3 13:35:02 2003
@@ -67,7 +67,8 @@
    * @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER.
    * @param miterlimit the limit to trim the miter join. The miterlimit must be
    * greater than or equal to 1.0f.
-   * @param dash The array representing the dashing pattern.
+   * @param dash The array representing the dashing pattern. There must be at
+   * least one non-zero entry.
    * @param dash_phase is negative and dash is not null.
    *
    * @exception IllegalArgumentException If one input parameter doesn't meet
@@ -76,13 +77,40 @@
   public BasicStroke(float width, int cap, int join, float miterlimit,
                      float[] dash, float dashPhase)
   {
-    if (width < 0 ||
-        miterlimit < 1.0f ||
-        cap < CAP_BUTT ||
-        cap > CAP_SQUARE ||
-        join < JOIN_MITER ||
-        join > JOIN_BEVEL)
-      throw new IllegalArgumentException();
+    if (width < 0.0f ) {
+      throw new IllegalArgumentException("width " + width + " < 0");
+    }
+    else if (cap < CAP_BUTT || cap > CAP_SQUARE) {
+      throw new IllegalArgumentException("cap " + cap + " out of range [" + CAP_BUTT + ".." + CAP_SQUARE + "]");
+    }
+    else if (miterlimit < 1.0f && join == JOIN_MITER) {
+      throw new IllegalArgumentException("miterlimit " + miterlimit + " < 1.0f while join == JOIN_MITER");
+    }
+    else if (join < JOIN_MITER || join > JOIN_BEVEL) {
+      throw new IllegalArgumentException("join " + join + " out of range [" + JOIN_MITER + ".." + JOIN_BEVEL + "]");
+    }
+    else if (dashPhase < 0.0f && dash != null) {
+      throw new IllegalArgumentException("dashPhase " + dashPhase + " < 0.0f while dash != null");
+    }
+    else if (dash != null) {
+      if (dash.length == 0) {
+	throw new IllegalArgumentException("dash.length is 0");
+      }
+      else {
+	boolean allZero = true;
+
+	for ( int i = 0; i < dash.length; ++i) {
+	  if (dash[i] != 0.0f) {
+	    allZero = false;
+	    break;
+	  }
+	}
+
+	if (allZero) {
+	  throw new IllegalArgumentException("all dashes are 0.0f");
+	}
+      }
+    }
 
     this.width = width;
     this.cap = cap;