Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
processing-bot opened this issue Feb 19, 2023 · 1 comment
Closed

Comments

@processing-bot
Copy link
Collaborator

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);
    }
  }
}
@processing-bot
Copy link
Collaborator Author

Created by: benfry

Thanks for the report and for looking into it. The problem is was that if (Double.isNaN(getFloat(row, column))) { was calling getFloat() instead of getDouble(). With that fixed, no crash. There's no else statement because it falls through to the end of the function, which uses String.valueOf() to return the value.

Fixed for Processing 4.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant