Repast / repast.simphony

Git repository for Repast Simphony development
repast.github.io
90 stars 21 forks source link

Resetting float range to default expects a double #70

Open MelchiorUU opened 2 years ago

MelchiorUU commented 2 years ago

Repast 2.9

I implemented a float range in the parameters for the GUI:

<parameter name="maxPassiveCertainty" displayName="1.4 Max passive certainty" type="float" 
        defaultValue="0.9" 
        isReadOnly="false" 
        converter="repast.simphony.parameter.StringConverterFactory$FloatConverter"
        range="0 1.0 .05"   
/>

Which gives the following error msg when I reset the run:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: class java.lang.Float cannot be cast to class java.lang.Double (java.lang.Float and java.lang.Double are in module java.base of loader 'bootstrap')
    at repast.simphony.ui.parameters.FPRangeParameterBinder.resetToDefault(FPRangeParameterBinder.java:64)
    at repast.simphony.ui.parameters.ParametersUI.resetParameters(ParametersUI.java:221)
    at repast.simphony.ui.GUIParametersManager.reset(GUIParametersManager.java:57)
    at repast.simphony.ui.GUIParametersManager.reset(GUIParametersManager.java:89)
    at repast.simphony.ui.RSApplication.reset(RSApplication.java:450)
    at repast.simphony.ui.action.ResetRun.actionPerformed(ResetRun.java:17)
    at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
    at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
    at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
    at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
    at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
    at java.desktop/java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:297)
    at java.desktop/java.awt.Component.processMouseEvent(Component.java:6635)
    at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
    at java.desktop/java.awt.Component.processEvent(Component.java:6400)
    at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5011)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2772)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

When looking at FPRangeParameterBinder.java:64 we see that it indeed expects a double and that there is no code of setting a float.

MelchiorUU commented 2 years ago

Ironically it seems that this bug is the result of the half fix that has been made after one of my previous reports: https://github.com/Repast/repast.simphony/commit/3d94293b92e56980793adb2893be34fb34e4f283

The initial setting of the parameter works, the error only happens on reset. I guess that is due to what is used for initialization:

double val = ((Number) params.getValue(name)).doubleValue();
...
SpinnerModel spinModel = new SpinnerNumberModel(val, min, max, spacing);

But that would imply that the spinner always converts things to double and putting float in paramters.xml is pointless for spinners ;-).