Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UIMA-6377] Spurious multipleReferencesAllowed warning when serializing empty arrays #133

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.uima.UimaSerializable;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASRuntimeException;
import org.apache.uima.cas.CommonArrayFS;
import org.apache.uima.cas.FSIndex;
import org.apache.uima.internal.util.Misc;
import org.apache.uima.internal.util.XmlElementName;
Expand Down Expand Up @@ -669,8 +670,9 @@ public void remove() {
* back into the serialized form; those might reference some of these.
*/
private void enqueueIncoming() {
if (sharedData == null)
if (sharedData == null) {
return;
}
TOP[] fss = this.sharedData.getAndSortByIdAllFSsInIdMap();
previouslySerializedFSs = new ArrayList<>();

Expand Down Expand Up @@ -729,8 +731,9 @@ private void enqueueIndexed() {
* been modified. The embedded nonshared-multivalued item could be a list or an array
*/
private void enqueueNonsharedMultivaluedFS() {
if (sharedData == null || !isDelta)
if (sharedData == null || !isDelta) {
return;
}
TOP[] fss = sharedData.getNonsharedMulitValuedFSs();
modifiedEmbeddedValueFSs = new ArrayList<>();

Expand Down Expand Up @@ -951,15 +954,21 @@ private boolean isMultiRef_enqueue(FeatureImpl fi, TOP featVal, boolean alreadyV
if (!isDynamicMultiRef) {

// not JSON dynamic embedding, or dynamic embedding is turned off - compute static embedding
// just for lists and arrays
// just for lists and arrays.
boolean multiRefAllowed = fi.isMultipleReferencesAllowed() || isListNode;
if (!multiRefAllowed) {
// Arrays cannot be resized, so it is ok if an empty array has multiple references to it
// even if multiRefAllowed is false because it is effectively immutable.
if ((featVal instanceof CommonArrayFS && ((CommonArrayFS<?>) featVal).isEmpty())) {
return false; // immutable empty array, no need to enqueue
}

// two cases: a list or non-list
// if a list, check/mark all the nodes in the list for any being multiply referenced
if ((isListFeat && isListElementsMultiplyReferenced(featVal)) ||
// say: multi-ref not allowed, but discovered a multi-ref, will be serialized as separate
// item
(!isListFeat && alreadyVisited)) {
if ((isListFeat && isListElementsMultiplyReferenced(featVal))
|| (!isListFeat && alreadyVisited)) {
reportMultiRefWarning(fi);
} else {
// multi-ref not allowed, and this item is not multiply referenced (so far)
Expand Down Expand Up @@ -1239,12 +1248,14 @@ public int compare(TOP fs1, TOP fs2) {
Annotation fs2a = (Annotation) fs2;

c = Integer.compare(fs1a.getBegin(), fs2a.getBegin());
if (c != 0)
if (c != 0) {
return c;
}

c = Integer.compare(fs2a.getEnd(), fs1a.getEnd()); // reverse order
if (c != 0)
if (c != 0) {
return c;
}

// fall thru to do id compare
}
Expand Down