Serial monitor: bug in Arduino 1.0.1

I think there's a bug in the serial monitor.
If you try a simple sketch like this:

void setup()
{
  delay(2000);  
  Serial.begin(19200);
}

void loop()
{
  Serial.println("Hello");
  delay(1000);
}

If you open the serial monitor and you have a baud rate different than the speed that you set into the sketch (i.e. 9600 bps), trying to change the baud speed will generate a Java error:

Experimental:  JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(String.java:1958)
	at processing.app.SerialMonitor$6.actionPerformed(SerialMonitor.java:137)
	at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1260)
	at javax.swing.JComboBox.setSelectedItem(JComboBox.java:588)
	at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:624)
	at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:835)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
	at java.awt.Component.processMouseEvent(Component.java:6505)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3312)
	at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:499)
	at java.awt.Component.processEvent(Component.java:6270)
	at java.awt.Container.processEvent(Container.java:2229)
	at java.awt.Component.dispatchEventImpl(Component.java:4861)
	at java.awt.Container.dispatchEventImpl(Container.java:2287)
	at java.awt.Component.dispatchEvent(Component.java:4687)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
	at java.awt.Container.dispatchEventImpl(Container.java:2273)
	at java.awt.Window.dispatchEventImpl(Window.java:2719)
	at java.awt.Component.dispatchEvent(Component.java:4687)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
	at java.awt.EventQueue.access$000(EventQueue.java:102)
	at java.awt.EventQueue$3.run(EventQueue.java:662)
	at java.awt.EventQueue$3.run(EventQueue.java:660)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
	at java.awt.EventQueue$4.run(EventQueue.java:676)
	at java.awt.EventQueue$4.run(EventQueue.java:674)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

(message kept under Arch Linux)
This happens with Linux and Windows versions of Arduino IDE.

The same operation can be done without issues with Arduino 0022.

Same for me under Windows 7

dalubar:
Same for me under Windows 7

+1
Same for me under Windows xp sp1, sp2 and Windows 7

No problem for me, on OS X.

No problem also for me, on Linux Debian.

the rror is here, SerialMonitor.java:

serialRates.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent event) {
        String wholeString = (String) serialRates.getSelectedItem();
        String rateString = wholeString.substring(0, wholeString.indexOf(' '));
        serialRate = Integer.parseInt(rateString);
        Preferences.set("serial.debug_rate", rateString);
        closeSerialPort();
        try {
          openSerialPort();
        } catch (SerialException e) {
          System.err.println(e);
        }
      }});

can you change it to

serialRates.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent event) {
	System.out.println("serialRates: "+(String) serialRates.getSelectedItem());
        String wholeString = (String) serialRates.getSelectedItem();
        System.out.println("wholeString: "+wholeString);
        String rateString = wholeString.substring(0, wholeString.indexOf(' '));
        System.out.println("wholeString: "+rateString);
        serialRate = Integer.parseInt(rateString);
        Preferences.set("serial.debug_rate", rateString);
        closeSerialPort();
        try {
          openSerialPort();
        } catch (SerialException e) {
          System.err.println(e);
        }
      }});

and tell me what appen? i can't reproduce the error!

I'm not able to recompile the IDE (no Java experience).

If you want to recompile the Arduino IDE under Linux, it's quite easy and doesn't need Java experience. The steps you must follow are:

  1. Download from Github the souce code of the Arduino IDE
  2. Make sure that on your linux box "apache ant" is installed, if not install it.
  3. Apply your modification to the code
  4. When you are ready to compile the IDE open a shell, move to the dir ".../Arduino/build" and type: ant; ant clean; ant build
  5. The build process will start and after it finishes you can launch the IDE using the command "ant run" or moving to the directory that the build process has generated: ".../Arduino/build/linux/work" and launch the IDE as usually.

i want to let you know that EVERY arduino 1.0.1 is afflicted by this problem, and i've open an issue with the solution:

http://code.google.com/p/arduino/issues/detail?id=964&can=6&sort=-id

thanks

OK. I'll follow the ticket.