При попытке выдать ошибку легко ее создать, если указать строку, когда она должна быть двойной или целой, что приводит к этой ошибке:

Exception in thread "pool-2-thread-5" Exception in thread "pool-2-thread-8" java.lang.RuntimeException: com.opencsv.exceptions.CsvDataTypeMismatchException: Konvertierung von OBST & GEMÜSE in double fehlgeschlagen.
    at com.opencsv.bean.concurrent.ProcessCsvLine.run(ProcessCsvLine.java:99)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: com.opencsv.exceptions.CsvDataTypeMismatchException: Konvertierung von OBST & GEMÜSE in double fehlgeschlagen.
    at com.opencsv.bean.ConverterPrimitiveTypes.convertToRead(ConverterPrimitiveTypes.java:128)
    at com.opencsv.bean.BeanFieldSingleValue.convert(BeanFieldSingleValue.java:98)
    at com.opencsv.bean.AbstractBeanField.setFieldValue(AbstractBeanField.java:180)
    at com.opencsv.bean.AbstractMappingStrategy.setFieldValue(AbstractMappingStrategy.java:581)
    at com.opencsv.bean.AbstractMappingStrategy.populateNewBean(AbstractMappingStrategy.java:328)
    at com.opencsv.bean.concurrent.ProcessCsvLine.processLine(ProcessCsvLine.java:128)
    at com.opencsv.bean.concurrent.ProcessCsvLine.run(ProcessCsvLine.java:83)
    ... 3 more
Caused by: org.apache.commons.beanutils.ConversionException: Error converting from 'String' to 'Double' For input string: "OBST & GEMÜSE"
    at org.apache.commons.beanutils.converters.AbstractConverter.handleError(AbstractConverter.java:282)
    at org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:177)
    at org.apache.commons.beanutils.converters.ConverterFacade.convert(ConverterFacade.java:61)
    at org.apache.commons.beanutils.ConvertUtilsBean.convert(ConvertUtilsBean.java:491)
    at com.opencsv.bean.ConverterPrimitiveTypes.convertToRead(ConverterPrimitiveTypes.java:118)
    ... 9 more
Caused by: java.lang.NumberFormatException: For input string: "OBST & GEMÜSE"
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
    at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    at java.lang.Double.parseDouble(Double.java:538)
    at java.lang.Double.<init>(Double.java:608)
    at org.apache.commons.beanutils.converters.NumberConverter.toNumber(NumberConverter.java:448)
    at org.apache.commons.beanutils.converters.NumberConverter.convertToType(NumberConverter.java:271)
    at org.apache.commons.beanutils.converters.AbstractConverter.convert(AbstractConverter.java:169)
    ... 12 more

Мой код выглядит так:

    for (Entry<Class<?>, Map<String, String>> entry : csvColumnTranslateMap.entrySet()) {

        @SuppressWarnings("rawtypes")
        HeaderColumnNameTranslateMappingStrategy strategy = new HeaderColumnNameTranslateMappingStrategy();
        strategy.setType(entry.getKey());
        strategy.setColumnMapping(entry.getValue());

        Reader reader = new InputStreamReader(file.getInputStream());

        CSVParser parser = new CSVParserBuilder().withSeparator(delimiter).withIgnoreQuotations(false).build();

        CSVReader csvReader = new CSVReaderBuilder(reader).withSkipLines(0).withCSVParser(parser).build();

        CsvToBean<?> csvToBean = new CsvToBean<>();

        csvToBean.setMappingStrategy(strategy);
        csvToBean.setCsvReader(csvReader);

        List<?> parsedRows = csvToBean.parse();

        if (entry.getKey().equals(Article.class)) {
            databaseConnector.saveAllArticles((List<Article>) parsedRows, articleRepository);
        } else if (entry.getKey().equals(CommidityGroup.class)) {
            databaseConnector.saveAllCommidityGroups((List<CommidityGroup>) parsedRows, commidityGroupRepository);
        } else if (entry.getKey().equals(Promotion.class)) {
            databaseConnector.saveAllPromotions((List<Promotion>) parsedRows, promotionRepository);
        } else if (entry.getKey().equals(Receipt.class)) {
            databaseConnector.saveAllReceipts((List<Receipt>) parsedRows, receiptRepository);
        } else if (entry.getKey().equals(Shop.class)) {
            databaseConnector.saveAllShops((List<Shop>) parsedRows, shopRepository);
        } else {
            System.err.println("Something went wrong");
        }

    }

Как я могу поймать это или проверить это даже раньше? Я попробовал попытку этого сайта https://sourceforge.net/p/opencsv/bugs/154/ но не помог мне.

0
CptDayDreamer