lbehnke / h2database

Automatically exported from code.google.com/p/h2database
0 stars 0 forks source link

NullPointerException at 1.1.114+ in FullText.hasChanged() #93

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Versions:
1.1.114
1.1.115

Steps to reproduce the problem:

1. Open database with fulltext index (with or without Lucene)
2. Update/set any indexed column with NULL value
3. Update the same indexed column within the same row with any other value 
(null or not) 
(MERGE INTO..)
4. --> NullPointerException at FullText.hasChanged() method

Analysis:

Source of this problem is the code change proposed in issue 84 and further 
discussed at issue 91 
(probably). 

Since version 1.1.114 full text triggers check if indexed column values have 
actually changed. To 
do this, they use the new FullText.hasChanged() method:

static boolean hasChanged(Object[] oldRow, Object[] newRow, int[] indexColumns) 
{
        for (int c : indexColumns) {
            Object o = oldRow[c], n = newRow[c];
            if (!o.equals(n)) {
                return true;
            }
        }
        return false;
    }

The problem is in direct equals comparison of old and new value in line 692:

if (!o.equals(n)) {

When old value is null, the equals comparison and subsequently the trigger 
fails with obvious 
NullPointerException.

Proposed fix:

Replace the comparison at line 692 with:

if ( ( o != null && ! o.equals(n) ) || ( o == null && n != null ) ) {

This correctly detects changes to previusly null column values.

Test case:

I have attached an updated TestFullText.java code (based one included 1.1.115 
source) to test for 
this issue (full code, not patch).

Original issue reported on code.google.com by ilkka.my...@gmail.com on 2 Jul 2009 at 10:25

Attachments:

GoogleCodeExporter commented 9 years ago
Hi,

Thanks! I already have a test case where I can reproduce this problem.
This bug is a duplicate of issue 91, it will be fixed in the next release.

Regards,
Thomas

Original comment by thomas.t...@gmail.com on 2 Jul 2009 at 8:13