tablesaw icon indicating copy to clipboard operation
tablesaw copied to clipboard

Table.read() null pointer exception

Open Afollet opened this issue 3 years ago • 2 comments

Hi, I've been using the library to read TSV's. I had a TSV that was blank. When the following method is used to read the TSV a null pointer exception is thrown. Could this be handled as an IOException instead?

public static Table readTsv(File file) throws IOException {
    CsvReadOptions.Builder builder = CsvReadOptions.builder(file).sample(false).separator('\t');
    CsvReadOptions options = builder.build();
    return Table.read().usingOptions(options);

Afollet avatar Nov 19 '21 16:11 Afollet

I have been eliminating the use of the checked IOException and replacing it with a new RuntimeIOException. (Because it is tedious in interactive use to be constantly catching IOExcpetion or adding it to a throws clause on so many methods). It could be made to throw that instead.

On Fri, Nov 19, 2021 at 11:38 AM Alex Follette @.***> wrote:

Hi, I've been using the library to read TSV's. I had a TSV that was blank. When the following method is used to read the TSV a null pointer exception is thrown. Could this be handled as an IOException instead?

public static Table readTsv(File file) throws IOException { CsvReadOptions.Builder builder = CsvReadOptions.builder(file).sample(false).separator('\t'); CsvReadOptions options = builder.build(); return Table.read().usingOptions(options);

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jtablesaw/tablesaw/issues/1037, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2FPASSTXBIQTN4VCDRVNTUMZ4QZANCNFSM5IMRQBQA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

lwhite1 avatar Nov 19 '21 19:11 lwhite1

Hey @lwhite1, I think RuntimeIOException would be a better solution. Instead of catching a NullPointerException I can catch RuntimeIOException. That would reduce the potential of the catch to hide bugs other bugs.

I am trying to avoid checking the file ( other than its existence ) before reading it in with Table.read(). It will reduce the amount of code I have to maintain for this project.

Thanks!

Afollet avatar Nov 22 '21 10:11 Afollet