Skip to content

Table::getString raises stackOverflowError on double value encounter #671

Closed
@processing-bot

Description

@processing-bot

Created by: Juicy8013

Description

The method Table::getString raises a stackOverflowError when it encounters a double value.

Expected Behavior

I was expecting to get a double value from the getString method.

Current Behavior

The getString method fails on returning a double value with a StackOverflowError.

Steps to Reproduce

  1. Create a table with at least 1 column of floating values and an arbitrary amount of rows:
// data/table.csv
0.001,0.002
0.001,0.002
0.001,0.002
0.001,0.002
  1. Load and save the table in the setup function:
// This works perfectly
void setup() {
  Table t = loadTable("data/table.csv", "csv");
  println(t.getString(2, 0));
}
  1. Then, edit the first column type:
// This raises a StackOverflowError
void setup() {
  Table t = loadTable("data/table.csv", "csv");
  t.setColumnType(0, Table.DOUBLE);
  println(t.getString(2, 0)); // right there
}
  1. Run the sketch.

Your Environment

  • Processing version: Processing 4.1.3-1, x86_64
  • Operating System and OS version: Arch Linux, Garuda Cinnamon 5.6.7, Kernel version: 6.1.12-zen1-1-zen
  • Other information:

Possible Causes / Solutions

After further investigation, it seems that the bug originated from the following statement, when a float is passed to the function call Double.isNan() and no else statement is defined:

// processing.data.Table::getString() - line 3553
    if (Double.isNaN(getFloat(row, column))) {
      return null;
    }
  }
  return String.valueOf(Array.get(columns[column], row));
}

I fixed the bug by overriding the method as follow:

// FixedTable.pde
import processing.data.Table;

class FixedTable extends Table {
  ...

  @Override
  public String getString(int row, int column) {
    checkBounds(row, column);
    if (Table.DOUBLE == this.getColumnType(column)) {
      double value =  this.getDouble(row, column);
      if (Double.isNaN(value)) {
        return null;
      } else {
        return Double.toString(value);
      }
    } else {
      return super.getString(row, column);
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions