Tools->Copy For Forum  Bug?

Often when I try to use the Copy For Forum menu item, I get this:

java.lang.ArrayIndexOutOfBoundsException: 37 at processing.app.tools.DiscourseFormat.formatCode(DiscourseFormat.java:204) at processing.app.tools.DiscourseFormat.show(DiscourseFormat.java:117) at processing.app.Editor$16$1.run(Editor.java:755) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)

When I restart my IDE everything is fine.

My system is: Windows XP Java 1.6.0_07 Arduino 0014 RXTX-2.1-7

With some special pde file?

Totally independent of file :(

Seems random.

By you error, it fail on:

char c = segmentArray[segmentOffset + offset];

in the function:

public String formatCode(int line) {

function dedicated to format each line of code for forum from:

    // Line by line
    for (int i = 0; i < parent.getLineCount(); i++) {
      cf.append(formatCode(i)); // <- called from here
    }

so the problem is with one of your lines, maybe you could test some codes and paste here any faulty one.

Every time I restart arduino IDE the code that once caused an error, does not. This makes me suspect the error is in the IDE not in my code. :)

You’re right :open_mouth: is the IDE

      for (;;) {
        byte id = tokens.id;
        if (id == Token.END) {
          char c = segmentArray[segmentOffset + offset];
          if (segmentOffset + offset < limit) {
            cf.append(c);
          } else {
            cf.append('\n');
          }
          return cf.toString();
        }

Fixed code:

      for (;;) {
        byte id = tokens.id;
        if (id == Token.END) {
          
          if (segmentOffset + offset < limit) {
                // BUGBUG: this has been modified :)
            cf.append(segmentArray[segmentOffset + offset]);
          } else {
            cf.append('\n');
          }
          return cf.toString();
        }

Try with my fixed version (it is not the 0015, just a patched 0014)
http://servicios.ried.cl/arduino/temp/pde_arduino-0015_fixed_2009-03-15.rar

extract that file to your arduino/lib/ path

What's the difference?

char c = segmentArray[segmentOffset + offset];
if (segmentOffset + offset < limit) { ...

The comprobation must be after the char asignation:

if (segmentOffset + offset < limit) { 
char c = segmentArray[segmentOffset + offset];

Small, but important detail.