Bug 46692

Summary: Boolean formula evaluation inverts result
Product: POI Reporter: Nick Giles <nick.giles>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: regression    
Priority: P2    
Version: 3.2-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

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.