cds-astro / cds-healpix-java

The CDS HEALPix library in Java
BSD 3-Clause "New" or "Revised" License
9 stars 9 forks source link

Tests for UltraCompactMOC fail with OpenJDK 11.0.3 #5

Closed mreineck closed 5 years ago

mreineck commented 5 years ago

When running the test suite, I get (among others) the following error:

    [junit] Testcase: test1(cds.healpix.HealpixNestedUltraCompactMOCTest):  Caused an ERROR
    [junit] Index 6 out of bounds for length 6
    [junit] java.lang.ArrayIndexOutOfBoundsException: Index 6 out of bounds for length 6
    [junit]     at cds.healpix.HealpixNestedUltraCompactMOC.bitSetFromBytes(HealpixNestedUltraCompactMOC.java:147)
    [junit]     at cds.healpix.HealpixNestedUltraCompactMOC.decompress(HealpixNestedUltraCompactMOC.java:153)
    [junit]     at cds.healpix.HealpixNestedUltraCompactMOCTest.test1(HealpixNestedUltraCompactMOCTest.java:72)
    [junit]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    [junit]     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

I'm pretty sure this happens because of the following code in HealpixNestedUltraCompactMOC.java:

    final BitSet bs = new BitSet(8 * compressedMoc.length);
    for (int i = 0; i < bs.size(); i++) {

Here, the implicit assumption seems to be that bs.size() is exactly equal to 8 * compressedMoc.length. But I don't think this is the case; the BitSet implementation may be allowed to round up its size to the nearest convenient value (e.g. the next multiple of 32). In this case the code above will break.

fxpineau commented 5 years ago

Correct. Again, I made too quick changes to be compatible with Java 6 (I also fix a bug ignoring the last value of a MOC).