pfalstad / circuitjs1

Electronic Circuit Simulator in the Browser
GNU General Public License v2.0
1.65k stars 280 forks source link

Bugfix: Exception when translating empty string #33

Closed fritzw closed 1 year ago

fritzw commented 1 year ago

When debugging this project using GWT 2.10.0 "Super Dev Mode" from the command line, it is not possible to open the EditDialog for a LabeledNodeElm. Instead a cryptic exception is thrown with the following message (the stack trace is unreadable):

Uncaught Error: com.google.gwt.event.shared.UmbrellaException: Exception caught: fromIndex: 0, toIndex: -1, length: 0

The error comes from the line s = s.substring(0, ix); in Locale.java, which evaluates to s.substring(0, -1) when the function is called with an empty string. Apparently GWT 2.10.0 does not like this. I thought about rewriting the indexOf check to use endsWith instead, which would correctly handle empty strings. But since "explicit is better than implicit" I added a special case check for empty strings instead.

fritzw commented 1 year ago

@pfalstad Oops, seems like it was a bad idea to make a pull request from master, since all those other commits should not be in here. I'll clean this up, split it into separate pull requests, and explain a bit more what the purpose of the changes is (if you are interested).

pfalstad commented 1 year ago

oops I forgot about these pull requests, sorry.. Thanks, I'll take a closer look.

pfalstad commented 1 year ago

ok you don't need to split these up. I have merged them into my local sandbox and will upload them soon. Thanks!

fritzw commented 1 year ago

Glad that you like it. However, we should probably add some documentation for the new features before they go live.

By the way, I'm also currently extending the GWT helper scripts to support those fancy "Cloud Dev Container" services like gitpod.io or GitHub Codespaces. That's why I proposed splitting those into a separate PR, since it's not done yet. But no harm done if you merge it in the current state.

I'm doing all development on circuitjs in those containers and it's really convenient. With the VSCode extension one can even forward the ports from docker to localhost, then it's exactly like developing locally, just without the need to set up anything. Much more accessible for new devs. :-)