Bug 46692 - Boolean formula evaluation inverts result
Summary: Boolean formula evaluation inverts result
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.2-FINAL
Hardware: PC Linux
: P2 regression (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-11 01:35 UTC by Nick Giles
Modified: 2009-02-11 10:20 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Giles 2009-02-11 01:35:09 UTC
It appears that the result of boolean formulae is being inverted when calculated. The following test case currently fails:

    public void testBooleanFunctions() {
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("test");
        HSSFRow row = sheet.createRow(0);

        HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(workbook);

        HSSFCell cell = row.createCell(0);

        cell.setCellFormula("AND(TRUE,TRUE)");
        evaluator.evaluateFormulaCell(cell);
        assertEquals("Should get correct boolean value", true, cell.getBooleanCellValue());

        cell = row.createCell(1);
        cell.setCellFormula("AND(TRUE,FALSE)");
        evaluator.evaluateFormulaCell(cell);
        assertEquals("Should get correct boolean value", false, cell.getBooleanCellValue());

    }

It appears there is a mismatch in org.apache.poi.hssf.record.FormulaRecord.SpecialCachedValue between the logic of createCachedBoolean and getBooleanValue

public static SpecialCachedValue createCachedBoolean(boolean b) {
  return create(BOOLEAN, b ? 0 : 1);
}

public boolean getBooleanValue() {
 ...
 return getDataValue() != 0;
}
Comment 1 Josh Micich 2009-02-11 10:20:12 UTC
Thanks for the detailed bug report.  This typo was spotted during the work on bug 46479 , and fixed in svn r731715 .  There were a few extra bugs found and fixed at the same time.  Junits were added for all fixed bugs but only the original bug is described in the bugzilla record. The bug you describe here (inverted conditinal operator) is identified by this junit:
TestFormulaRecord.testCachedValue_bug46479().


This fix made it into the recent release, 3.5-beta5.