Skip to content

Commit 5e0e6a0

Browse files
committed
ODFTOOLKIT-187: fix results of PuzzlePiece.extractPuzzlePieces()
This created nondeterministic and wrong results, somewhere in reduceAttributes(). 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)
1 parent 8256ac4 commit 5e0e6a0

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

generator/schema2template/src/main/java/schema2template/model/PuzzlePiece.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public int compareTo(PuzzlePiece o) {
192192
if (retval != 0) {
193193
return retval;
194194
}
195-
return hashCode() - o.hashCode();
195+
return Integer.compare(hashCode(), o.hashCode());
196196
}
197197

198198
/*

generator/schema2template/src/test/java/schema2template/example/odf/PuzzlePieceTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.util.logging.Level;
3636
import java.util.logging.Logger;
3737
import org.junit.Assert;
38-
import org.junit.Ignore;
3938
import org.junit.Test;
4039
import schema2template.model.MSVExpressionIterator;
4140
import schema2template.model.PuzzlePiece;
@@ -54,7 +53,7 @@ public class PuzzlePieceTest {
5453
private static final String OUTPUT_REF_ODF12 =
5554
TEST_REFERENCE_DIR + File.separator + "odf12-msvtree.ref";
5655
private static final int ODF12_ELEMENT_DUPLICATES = 7;
57-
private static final int ODF12_ATTRIBUTE_DUPLICATES = 134;
56+
private static final int ODF12_ATTRIBUTE_DUPLICATES = 116;
5857

5958
/**
6059
* Test: Use the MSV
@@ -155,7 +154,6 @@ private String readFileAsString(String filePath) throws java.io.IOException {
155154
* extract PuzzlePieces out of a XML schema
156155
*/
157156
@Test
158-
@Ignore // due to issue https://issues.apache.org/jira/browse/ODFTOOLKIT-180
159157
public void testExtractPuzzlePieces() {
160158
try {
161159
PuzzlePieceSet allElements_ODF11 = new PuzzlePieceSet();
@@ -189,7 +187,6 @@ public void testExtractPuzzlePieces() {
189187
* extract PuzzlePieces out of a XML schema
190188
*/
191189
@Test
192-
@Ignore
193190
public void testExtractPuzzlePiecesWithDuplicates() {
194191
try {
195192
PuzzlePieceSet allElements_ODF12 = new PuzzlePieceSet();

0 commit comments

Comments
 (0)