You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2023/04/16 14:04:00 UTC

[jira] [Commented] (CSV-307) Exception change in CSVParser.getNextRecord() raises minimum Android version

    [ https://issues.apache.org/jira/browse/CSV-307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17712787#comment-17712787 ] 

Gary D. Gregory commented on CSV-307:
-------------------------------------

Hello [~thelastproject]

The requirement for this component is Java 8. Whatever Android does when it slices and dices Java API support is outside the scope this component IMO. I'm not even sure we can find out what Android version a Maven project requires. Are you aware of a Maven plugin we could use to document what Android version a project requires?

> Exception change in CSVParser.getNextRecord() raises minimum Android version
> ----------------------------------------------------------------------------
>
>                 Key: CSV-307
>                 URL: https://issues.apache.org/jira/browse/CSV-307
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.10.0
>            Reporter: Sylvia van Os
>            Priority: Major
>
> I have an Android project targeting minSdk 21 (Android 5). Recently, dependabot offered 1.10.0 as an update for commons-csv.
> 1.10.0 changes the behaviour of org.apache.commons.csv.CSVParser$CSVRecordIterator.getNextRecord to throw an java.io.UncheckedIOException instead of an IllegalArgumentException or IllegalStateException (I wrote the code long ago and am no longer sure which of the two exceptions has been replaced).
> I use the following input:
> {code:java}
>         String csvText = "2\n" +
>                 "\n" +
>                 "_id\n" +
>                 "Health\n" +
>                 "Food\n" +
>                 "Fashion\n" +
>                 "\n" +
>                 "_id,store,note,validfrom,expiry,balance,balancetype,cardid,barcodeid,headercolor,barcodetype,starstatus\n" +
>                 "1,Card 1,Note 1,1601510400,1618053234,100,USD,1234,5432,1,QR_CODE,0,\r\n" +
>                 "8,Clothes Store,Note about store,,,0,,a,,-5317,,0,\n" +
>                 "2,Department Store,,,1618041729,0,,A,,-9977996,,0,\n" +
>                 "3,Grocery Store,\"Multiline note about grocery store\n" +
>                 "\n" +
>                 "with blank line\",,,150,,dhd,,-9977996,,0,\n" +
>                 "4,Pharmacy,,,,0,,dhshsvshs,,-10902850,,1,\n" +
>                 "5,Restaurant,Note about restaurant here,,,0,,98765432,23456,-10902850,CODE_128,0,\n" +
>                 "6,Shoe Store,,,,12.50,EUR,a,-5317,,AZTEC,0,\n" +
>                 "\n" +
>                 "cardId,groupId\n" +
>                 "8,Fashion\n" +
>                 "3,Food\n" +
>                 "4,Health\n" +
>                 "5,Food\n" +
>                 "6,Fashion\n";
> {code}
> (Source: https://github.com/CatimaLoyalty/Android/blob/19f406cd8c5fc0defe0948e8ec7b391514dbb408/app/src/main/java/protect/card_locker/importexport/CatimaImporter.java#L108-L169)
> which gets read line-by-line until whitespace is found. This causes the following invalid CSV to given to the CSVParser on the first pass:
> {code}
> _id,store,note,validfrom,expiry,balance,balancetype,cardid,barcodeid,headercolor,barcodetype,starstatus
> 1,Card 1,Note 1,1601510400,1618053234,100,USD,1234,5432,1,QR_CODE,0,
> 8,Clothes Store,Note about store,,,0,,a,,-5317,,0,
> 2,Department Store,,,1618041729,0,,A,,-9977996,,0,
> 3,Grocery Store,"Multiline note about grocery store
> {code}
> In the following code snippet, this used to first throw an IllegalArgumentException or an IllegalStateException, but now throws and UncheckedIOException:
> {code:java}
>         final CSVParser cardParser = new CSVParser(new StringReader(data), CSVFormat.RFC4180.builder().setHeader().build());
>         List<CSVRecord> records = new ArrayList<>();
>         try {
>             for (CSVRecord record : cardParser) {
>                 records.add(record);
>                 if (Thread.currentThread().isInterrupted()) {
>                     throw new InterruptedException();
>                 }
>             }
>         } catch (IllegalArgumentException | IllegalStateException e) {
>             throw new FormatException("Issue parsing CSV data", e);
>         } finally {
>             cardParser.close();
>         }
> {code}
> (Source: https://github.com/CatimaLoyalty/Android/blob/19f406cd8c5fc0defe0948e8ec7b391514dbb408/app/src/main/java/protect/card_locker/importexport/CatimaImporter.java#L198-L214)
> Trying to change the catch statement to catch UncheckedIOException instead, gives the following error in Android Studio: "Exception requires API level 24 (current min is 21): java.io.UncheckedIOException".
> Effectively, this means the minimal Android version for some parts of this library is now Android 7.
> Is this bump in minimal Android version for certain parts of the codebase intended? The changelogs on https://commons.apache.org/proper/commons-csv/changes-report.html#a1.10.0 do not seem to suggest any such thing.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)