Skip to content


ODFTOOLKIT-187: fix results of PuzzlePiece.extractPuzzlePieces()
Browse files Browse the repository at this point in the history
This created nondeterministic and wrong results, somewhere in

The reason appears to be that there are ordered containers like a
TreeSet<PuzzlePiece> in uniteDefinitionsWithEqualContent() involved
and the PuzzlePiece.compareTo() has a problem with overflow, so it
sometimes returns wrong results and then the TreeSet will be wrongly
sorted and it can't find some elements.

Just compare the integers properly and the result is deterministic.

(cherry picked from commit 335bab8)
  • Loading branch information
mistmist committed Jun 9, 2021
1 parent 8256ac4 commit 5e0e6a0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public int compareTo(PuzzlePiece o) {
if (retval != 0) {
return retval;
return hashCode() - o.hashCode();
return, o.hashCode());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import schema2template.model.MSVExpressionIterator;
import schema2template.model.PuzzlePiece;
Expand All @@ -54,7 +53,7 @@ public class PuzzlePieceTest {
private static final String OUTPUT_REF_ODF12 =
TEST_REFERENCE_DIR + File.separator + "odf12-msvtree.ref";
private static final int ODF12_ELEMENT_DUPLICATES = 7;
private static final int ODF12_ATTRIBUTE_DUPLICATES = 134;
private static final int ODF12_ATTRIBUTE_DUPLICATES = 116;

* Test: Use the MSV
Expand Down Expand Up @@ -155,7 +154,6 @@ private String readFileAsString(String filePath) throws {
* extract PuzzlePieces out of a XML schema
@Ignore // due to issue
public void testExtractPuzzlePieces() {
try {
PuzzlePieceSet allElements_ODF11 = new PuzzlePieceSet();
Expand Down Expand Up @@ -189,7 +187,6 @@ public void testExtractPuzzlePieces() {
* extract PuzzlePieces out of a XML schema
public void testExtractPuzzlePiecesWithDuplicates() {
try {
PuzzlePieceSet allElements_ODF12 = new PuzzlePieceSet();
Expand Down

0 comments on commit 5e0e6a0

Please sign in to comment.