Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0052415Openbravo ERPA. Platformpublic2023-05-10 23:202023-05-29 10:13
jlopez 
frank_gonzalez 
normalminorsometimes
acknowledgedopen 
5
 
 
Core
No
0052415: Error importing text files: Input length = 1
It has been detected that when importing text files, depending on the operating system with which the file was generated, it can generate the following exception:

java.nio.charset.MalformedInputException: Input length = 1

Specifically, for now the error has been located when importing text files that are then processed reading line by line, since depending on the operating system that generated the file, it could use a different line break character than the default for UNIX systems (LF).

Creating BufferedReader from Files.newBufferedReader, when running the application it may throw the exception mentioned above. Example:

Files.newBufferedReader(Paths.get("a.txt"), StandardCharsets.UTF_8);

But if we replace the above with this, it works well:

new BufferedReader(new InputStreamReader(new FileInputStream("a.txt"),"utf-8"));

The different is that, the former uses CharsetDecoder default action (The default action for malformed-input and unmappable-character errors is to report them), while the latter uses the REPLACE action:

cs.newDecoder().onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE)

Tests have been done in this regard and it has been verified that using the replacement avoids the error and imports the file correctly (at least for the specific case of line breaks).

The use of the same case has been detected in the following files:
- src/org/openbravo/retail/discounts/bytotal/actionhandler/ImportFreeProductInDiscount.java
- src/org/openbravo/retail/discounts/actionhandler/ImportFreeProductInDiscount.java
- src/org/openbravo/pos2/process/ImportCrossStoreWithPriority.java
- src/org/openbravo/pos2/process/ImportStoreSet.java
- src/org/openbravo/reporting/tools/task/ImportLabelsTask.java
- src/org/openbravo/reporting/tools/task/GenerateJasperPropertyFileTask.java

So perhaps it would be necessary to check if it is necessary to apply any correction.
*
Replace this:

Files.newBufferedReader(Paths.get(file.getAbsolutePath()))

For this:

new BufferedReader(new InputStreamReader(new FileInputStream(file.getAbsolutePath())))
No tags attached.
related to defect 0052368 closed jlopez Modules [OPECOM] Cannot import prices : error Input lenght = 1 
Issue History
2023-05-10 23:20jlopezNew Issue
2023-05-10 23:20jlopezAssigned To => Triage Platform Base
2023-05-10 23:20jlopezModules => Core
2023-05-10 23:20jlopezTriggers an Emergency Pack => No
2023-05-10 23:21jlopezRelationship addedrelated to 0052368
2023-05-11 09:40aferrazAssigned ToTriage Platform Base => Triage Omni OMS
2023-05-25 10:54frank_gonzalezAssigned ToTriage Omni OMS => frank_gonzalez
2023-05-25 10:55frank_gonzalezStatusnew => acknowledged
2023-05-29 10:12hgbotNote Added: 0150367
2023-05-29 10:13hgbotNote Added: 0150368
2023-05-29 10:13hgbotNote Added: 0150369

Notes
(0150367)
hgbot   
2023-05-29 10:12   
Merge Request created: https://gitlab.com/openbravo/product/pmods/org.openbravo.pos2/-/merge_requests/1849 [^]
(0150368)
hgbot   
2023-05-29 10:13   
Merge Request created: https://gitlab.com/openbravo/product/pmods/org.openbravo.retail.discounts/-/merge_requests/105 [^]
(0150369)
hgbot   
2023-05-29 10:13   
Merge Request created: https://gitlab.com/openbravo/product/pmods/org.openbravo.reporting.tools/-/merge_requests/16 [^]