Dear List Members,
I downloaded the latest source of MASON and made some minor
modifications on the code (some errors caused by typos, created but not
thrown exceptions, some NPEs, corrected error messages and alike).
Hope you may find them useful.
Best regards,
Richard
--
Richard O. Legendi
Software developer
Intelligent Applications and Web Services
AITIA International, Inc.
http://people.inf.elte.hu/legendi/
Index: sim/field/network/Edge.java
===================================================================
--- sim/field/network/Edge.java (revision 584)
+++ sim/field/network/Edge.java (working copy)
@@ -100,7 +100,9 @@
this.to = to;
this.info = info;
this.indexFrom = indexFrom;
- this.indexFrom = indexTo;
+ //this.indexFrom = indexTo;
+ // I guess this should be an indexTo assignment:
+ this.indexTo = indexTo;
}
/**
@@ -147,6 +149,13 @@
}
+ // Note: if compareTo() returns 0 then equals() should return true as well
+ // However, the equals() method is not overridden. See the Javadoc of
+ // Comparable:
+ // "It is strongly recommended, but not strictly required that
+ // (x.compareTo(y)==0) == (x.equals(y))."
+ // This may result in weird stuff when using Edges with something like
+ // PriorityQueues
public int compareTo(Object obj)
{
if (info == null || obj == null || !(obj instanceof Edge))
Index: sim/engine/Schedule.java
===================================================================
--- sim/engine/Schedule.java (revision 584)
+++ sim/engine/Schedule.java (working copy)
@@ -673,8 +673,13 @@
public boolean equals(Object obj)
{
- Key o = (Key)obj;
- return (o.time == time && o.ordering == ordering);
+ // ERROR Preparing for null and non-Key parameters
+ if (obj instanceof Key)
+ {
+ Key o = (Key)obj;
+ return (o.time == time && o.ordering == ordering);
+ }
+ return false;
}
public int hashCode()
Index: sim/util/gui/MiniHistogram.java
===================================================================
--- sim/util/gui/MiniHistogram.java (revision 584)
+++ sim/util/gui/MiniHistogram.java (working copy)
@@ -186,7 +186,11 @@
String[] s = new String[numBuckets];
if (min>max) {double tmp = min; min = max; max = tmp;} // duh, stupid user
- else if (min==max) { s[0] = "["+min+"..."+max+"]"; for(int x=1;x<s.length;x++) s[x] = ""; return s;} // duh, stupider user
+
+ // I'm not sure about this, but I guess the following has nothing to do with the previous if-else
+ // E.g., if min > max, then an array of nulls returned
+
+ if (min==max) { s[0] = "["+min+"..."+max+"]"; for(int x=1;x<s.length;x++) s[x] = ""; return s;} // duh, stupider user
else if (logScale)
{
min = Math.log(min);
Index: sim/util/media/MovieEncoder.java
===================================================================
--- sim/util/media/MovieEncoder.java (revision 584)
+++ sim/util/media/MovieEncoder.java (working copy)
@@ -464,7 +464,8 @@
boolean endAcknowledged = false;
float frameRate;
- MovieEncoderDataStream(Format format, float frameRate) { frameRate = this.frameRate ;this.format = format; }
+ // ERROR wrong assignment
+ MovieEncoderDataStream(Format format, float frameRate) { this.frameRate = frameRate ;this.format = format; }
void finish()
{
Index: sim/util/media/chart/MinGapDataCuller.java
===================================================================
--- sim/util/media/chart/MinGapDataCuller.java (revision 584)
+++ sim/util/media/chart/MinGapDataCuller.java (working copy)
@@ -181,7 +181,7 @@
}
//I prefer to drop the point the leaves behind the smallest gap (key=leftGap+rightGap)
//In case of a tie, I prefer to dop the first point (so I keep more of the fresh data on)
- public int compareTo(Object o)
+ public int compareTo(Object o) // See comment for sim.field.network.Edge, same stands here
{
Record r = (Record)o;
double keydiff = key-r.key;
Index: sim/util/media/chart/ScatterPlotSeriesAttributes.java
===================================================================
--- sim/util/media/chart/ScatterPlotSeriesAttributes.java (revision 584)
+++ sim/util/media/chart/ScatterPlotSeriesAttributes.java (working copy)
@@ -6,23 +6,24 @@
package sim.util.media.chart;
-import java.awt.*;
-import javax.swing.*;
-import javax.swing.border.*;
-import java.awt.geom.*;
-import java.awt.event.*;
-import java.util.*;
-import sim.util.gui.*;
+import java.awt.Color;
+import java.awt.Shape;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Rectangle2D;
+import java.util.Arrays;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
-// From JFreeChart (jfreechart.org)
-import org.jfree.data.xy.*;
-import org.jfree.chart.*;
-import org.jfree.chart.event.*;
-import org.jfree.chart.plot.*;
-import org.jfree.data.general.*;
-import org.jfree.chart.renderer.xy.*;
-import org.jfree.data.general.*;
-import org.jfree.data.xy.*;
+import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
+import org.jfree.data.general.SeriesChangeListener;
+
+import sim.util.gui.ColorWell;
+import sim.util.gui.NumberTextField;
public class ScatterPlotSeriesAttributes extends SeriesAttributes
{
@@ -130,7 +131,8 @@
public void setName(String val)
{
- setName(val);
+ //setName(val); // ERROR Isn't this an infinite recursion?
+ super.setName(val); // I guess this was intended, right?
((ScatterPlotGenerator)generator).update();
}
Index: sim/util/CausedRuntimeException.java
===================================================================
--- sim/util/CausedRuntimeException.java (revision 584)
+++ sim/util/CausedRuntimeException.java (working copy)
@@ -45,9 +45,11 @@
if (target == null) // duh, need to print our own stack trace
super.printStackTrace();
else
- stream.println("CausedRuntimeException: " + message);
- stream.println("Caused By:");
- target.printStackTrace(stream);
+ {
+ stream.println("CausedRuntimeException: " + message);
+ stream.println("Caused By:");
+ target.printStackTrace(stream); // Here it may be null otherwise
+ }
}
public void printStackTrace(PrintWriter stream)
@@ -55,9 +57,11 @@
if (target == null) // duh, need to print our own stack trace
super.printStackTrace();
else
+ {
stream.println("CausedRuntimeException: " + message);
- stream.println("Caused By:");
- target.printStackTrace(stream);
+ stream.println("Caused By:");
+ target.printStackTrace(stream); // Here it may be null otherwise
+ }
}
public void printStackTrace() { printStackTrace(System.err); }
Index: sim/util/distribution/Gamma.java
===================================================================
--- sim/util/distribution/Gamma.java (revision 584)
+++ sim/util/distribution/Gamma.java (working copy)
@@ -118,7 +118,7 @@
// Check for invalid input values
if (a <= 0.0) throw new IllegalArgumentException();
- if (lambda <= 0.0) new IllegalArgumentException();
+ if (lambda <= 0.0) throw new IllegalArgumentException(); // ERROR Forgot to throw the created exception
if (a < 1.0) { // CASE A: Acceptance rejection algorithm gs
b = 1.0 + 0.36788794412 * a; // Step 1
Index: sim/app/balls3d/Balls3D.java
===================================================================
--- sim/app/balls3d/Balls3D.java (revision 584)
+++ sim/app/balls3d/Balls3D.java (working copy)
@@ -13,8 +13,6 @@
public class Balls3D extends SimState
{
- private static final long serialVersionUID = 1;
-
public Continuous3D balls;
public Network bands;
Index: sim/app/particles3d/Particles3D.java
===================================================================
--- sim/app/particles3d/Particles3D.java (revision 584)
+++ sim/app/particles3d/Particles3D.java (working copy)
@@ -63,5 +63,4 @@
System.exit(0);
}
- static final long serialVersionUID = 9115981605874680023L;
}
Index: sim/app/cto/KMeansEngine.java
===================================================================
--- sim/app/cto/KMeansEngine.java (revision 584)
+++ sim/app/cto/KMeansEngine.java (working copy)
@@ -10,7 +10,7 @@
public /*strictfp*/ class KMeansEngine
{
- private static final long serialVersionUID = 1;
+ // private static final long serialVersionUID = 1; // Unused
final static double ALFA = 0.25;
@@ -52,6 +52,12 @@
public Double2D getGoalPosition( int id )
{
+ // ERROR There may be some serious synchronization issues here.
+ // Since basically there are only two Boolean instances (Boolean.TRUE
+ // and Boolean.FALSE), they are synchronizing on the same object
+ // instances everywhere in the code.
+ //
+ // By default, all of the usable[] elements refer to Boolean.FALSE.
synchronized( usable[id] )
{
if( usable[id].booleanValue() )
@@ -111,6 +117,7 @@
}
for( int i = 0 ; i < CooperativeObservation.NUM_AGENTS ; i++ )
{
+ // ERROR Same comment as above with Synchronizing on Booleans
synchronized( usable[i] )
{
if( n[i] != 0 )
Index: sim/portrayal/network/SimpleEdgePortrayal2D.java
===================================================================
--- sim/portrayal/network/SimpleEdgePortrayal2D.java (revision 584)
+++ sim/portrayal/network/SimpleEdgePortrayal2D.java (working copy)
@@ -247,7 +247,7 @@
labelFont.getSize2D();
if (scaledFont == null ||
scaledFont.getSize2D() != size ||
- scaledFont.getFamily() != labelFont.getFamily() ||
+ ! scaledFont.getFamily().equals( labelFont.getFamily() ) || // ERROR These are strings
scaledFont.getStyle() != labelFont.getStyle())
scaledFont = this.scaledFont = labelFont.deriveFont(size);
|