defano / wyldcard

A clone of Apple's HyperCard and HyperTalk scripting language.
https://github.com/defano/wyldcard/wiki
MIT License
117 stars 12 forks source link

NumberFormatException (locale-related) #90

Open rozek opened 2 years ago

rozek commented 2 years ago

Good morning!

I just tried to resize a stack to 1280x1024 pixels from within "Stack Info..." > "Resize...", but failed with the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "1.280"
        at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
        at java.base/java.lang.Integer.parseInt(Integer.java:658)
        at java.base/java.lang.Integer.parseInt(Integer.java:776)
        at com.defano.wyldcard.window.layout.StackSizeEditor.onOK(StackSizeEditor.java:48)
        at com.defano.wyldcard.window.layout.StackSizeEditor.lambda$new$0(StackSizeEditor.java:30)
        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.Component.processMouseEvent(Component.java:6636)
        at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
        at java.desktop/java.awt.Component.processEvent(Component.java:6401)
        at java.desktop/java.awt.Container.processEvent(Container.java:2263)
        at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
        at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
        at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
        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:2762)
        at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
        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(AccessController.java:391)
        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(AccessController.java:391)
        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.pumpEventsForFilter(EventDispatchThread.java:117)
        at java.desktop/java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190)
        at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:235)
        at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:233)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
        at java.desktop/java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:233)
        at java.desktop/java.awt.Dialog.show(Dialog.java:1070)
        at java.desktop/java.awt.Component.show(Component.java:1716)
        at java.desktop/java.awt.Component.setVisible(Component.java:1663)
        at java.desktop/java.awt.Window.setVisible(Window.java:1021)
        at java.desktop/java.awt.Dialog.setVisible(Dialog.java:1005)
        at com.defano.wyldcard.window.layout.StackSizeEditor.editStackSize(StackSizeEditor.java:79)
        at com.defano.wyldcard.window.layout.StackPropertyEditor.lambda$new$2(StackPropertyEditor.java:44)
        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.Component.processMouseEvent(Component.java:6636)
        at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
        at java.desktop/java.awt.Component.processEvent(Component.java:6401)
        at java.desktop/java.awt.Container.processEvent(Container.java:2263)
        at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
        at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
        at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
        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:2762)
        at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
        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(AccessController.java:391)
        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(AccessController.java:391)
        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.pumpEventsForFilter(EventDispatchThread.java:117)
        at java.desktop/java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190)
        at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:235)
        at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:233)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
        at java.desktop/java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:233)
        at java.desktop/java.awt.Dialog.show(Dialog.java:1070)
        at java.desktop/java.awt.Component.show(Component.java:1716)
        at java.desktop/java.awt.Component.setVisible(Component.java:1663)
        at java.desktop/java.awt.Window.setVisible(Window.java:1021)
        at java.desktop/java.awt.Dialog.setVisible(Dialog.java:1005)
        at com.defano.wyldcard.window.WyldCardDialog.setVisible(WyldCardDialog.java:83)
        at com.defano.wyldcard.window.WindowBuilder.build(WindowBuilder.java:198)
        at com.defano.wyldcard.part.model.PartModel.lambda$editProperties$15(PartModel.java:529)
        at com.defano.wyldcard.thread.Invoke.onDispatch(Invoke.java:156)
        at com.defano.wyldcard.part.model.PartModel.editProperties(PartModel.java:487)
        at com.defano.wyldcard.menu.main.ObjectsMenu.lambda$new$7(ObjectsMenu.java:51)
        at com.defano.wyldcard.menu.dispatcher.MenuMessageHandler.lambda$handleMessage$0(MenuMessageHandler.java:39)
        at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:303)
        at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
        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(AccessController.java:391)
        at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
        at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
        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)

Underlying reason: whenever I enter a number >=1000, an extra dot is shown in (and inserted into) the number input field ("1000" => "1.000") but this extra dot crashes "parseInt".

Nota bene: set the width of this stack to 1280 works fine!

Consequence: independent of what the original HyperCard is supporting - I recommend fixing the WyldCard locale to "english" (unless you have so much extra resources that you can investigate any problems with other locales and fix them...)

Appropriate changes to the documentation will inform any users about this "restriction".

defano commented 2 years ago

Hi @rozek , I concur.

I think this can be solved by adding a statement like Locale.setDefault(Locale.ENGLISH); somewhere in WyldCard.java (probably in main() or startup()).

Happy to accept a PR if you'd like to make the change, or I will try to get to this over the weekend.

rozek commented 2 years ago

I've just added the suggested change to my pending PR.

While it fixes the bug, I'm not quite happy with the resulting behaviour (but perhaps you want it so?): as soon as I enter a number > 999 into an input field and move on to another field (i.e., the original field looses its focus), the entered number is reformatted with an inner comma to separate the thousands from the hundreds. Since commas have a purpose within HyperTalk, I'd recommend to change the number formatting as well...

Amendment: explicitly setting the default locale to ENGLISH also seems to fix issue #85 - at least, gradlew clean followed by gradlew run worked without any problems. If you can live with the implications (no locale-specific dates, times, numbers etc.) that could be a solution...