#1522·CoreNLP

utils bugs

Author: AngledLuffaCreated Sep 28, 2026Updated Sep 28, 2026

for anyone scrolling through here - no, we don't need LLM generated PRs to fix any of these. thanks for asking.

Suspected bugs in edu.stanford.nlp.util

These turned up while documenting edu.stanford.nlp.util for javadoc. None of them were fixed; the javadoc changes don't change behaviour. Line numbers are for the files in util-javadoc-warnings.zip, which have extra doc lines, so treat them as approximate and go by the method name. (doc) means the new javadoc describes the current, buggy behaviour. If you fix the bug, update that doc too.

Always fails, or wrong on common paths

  • Functions.compose (doc): the arguments are handed to ComposedFunction(g, f) in the wrong order, so the result computes f(g(x)) instead of g(f(x)). The raw type hides this from the compiler.
  • DeltaCollectionValuedMap.remove / clear: both store a plain Object marker cast to Collection, so remove always throws ClassCastException. get, add and removeMapping fail the same way on a key that was marked removed.
  • MemoryMonitor.pollFree: collects at most 2 fields and then reads l.get(2). The exception is caught and logged, and usedSwap is never set.
  • ConvertByteArray
    • The char readers don't mask the low byte with & 0xff, so any char whose low byte is 0x80 or higher reads back wrong (é becomes U+FFE9). Lines around 261, 279, 303, 987 and 1003.
    • byteArrToLongArr: an int is shifted by up to 56 bits, which corrupts the upper 4 bytes. byteArrToDoubleArr casts to (long) first and gets this right.
    • shortArrToByteArr writes with a stride of 4 bytes but reads back with a stride of 2. The 3-argument version overflows for more than one value.
    • booleanArrToByteArr(..., off, ...) ignores off.
    • The *ArrToByteArr subrange versions size their output with s.length instead of length.
    • The 5-argument byteArrToUStringArr and byteArrToAStringArr read s[i] where they should read s[i + pos].
    • readDoubleArr and readFloatArr use a single read(), not readFully.
  • TwoDimensionalSet.add (doc): returns true when the pair was already present, the opposite of Set.add. addAll and addAllKeys inherit this.
  • TwoDimensionalSet.remove (doc): unboxes a null Boolean when the pair is absent and throws a NullPointerException. removeAll fails the same way.
  • IterableIterator(Stream) (doc): iterator() and spliterator() run a second terminal operation on the stream and throw IllegalStateException, so a for-each over one fails.
  • FixedPrioritiesPriorityQueue: iterator() goes through toSortedList(), which drains the queue. Any iteration, including inherited AbstractSet methods, empties it. getPriority on a missing key throws; the interface says it returns -Infinity.
  • HashIndex.loadFromReader: continue skips the readLine(), so a line with no =, or ending in =, causes an infinite loop.
  • MetaClass.castWithoutKnowingType (doc): A && !B || C parses as (A && !B) || C. Any value containing a space skips every type, String included, and returns null.
  • ArgumentParser: a required option that has alt names reports "Missing required option" for every name that wasn't the one actually used.
  • MulticoreWrapper: when a processor throws, it puts a null into a ConcurrentHashMap, which throws a NullPointerException. The processor id is never returned, so join() hangs.
  • SystemUtils.ProcessOutputStream.close(): joins StreamGobbler threads that only stop after kill(), and nothing calls kill(). It appears to hang forever.

Wrong results in edge cases

  • UnorderedPair.compareTo
    • other1/other2 are taken from this, not from other.
    • The second-element branch returns c1, which is 0 at that point, instead of c2.
  • DeltaIndex.objectsList: tests result.size() > backingIndexSize on the still-empty result. It should use backingIndex.size().
  • DeltaMap.clear(): keys that were only added through put survive the clear.
  • Iterables.merge (two-way): the last matching pair can be lost when one iterator runs out. For example, [1,2] merged with [2] never yields (2,2).
  • CollectionUtils.concatIterators: hasNext() is false if the first iterator starts out empty, even when later ones have elements.
  • ConcatenationIterator.remove(): after the last element of first, it removes from second.
  • StringUtils
    • nthIndex (doc) never counts a match at position 0.
    • toAscii maps Ì Í Î Ï to "F".
    • toAscii tests c <= 0x2014 where it should test 0x2013, so all of Greek, Cyrillic, Arabic and CJK become "-".
    • resolveVars supports only ${VAR}, not the documented $VAR. Its replacement isn't passed through quoteReplacement, so a value containing $ or \ breaks it.
    • toTitleCase and isAllUpperCase cast code points to char, which corrupts non-BMP characters.
    • searchAndReplace (doc) escapes only . [ ] \.
    • makeTextTable misaligns the header row when rowLabels is null.
  • ArrayUtils
    • deltaDecode(byte[], start, end) (doc) ignores the range.
    • equals(boolean[][], boolean[][]) returns false for two nulls; the int and double versions return true.
    • removeAt(Object[], int) uses array[0].getClass() for the new array.
    • getSubListIndex loops forever when tofind is empty.
  • Interval
    • checkMultipleBitSet always returns false, so REL_FLAGS_INTERVAL_FUZZY is never set.
    • REL_FLAGS_INTERVAL_ALMOST_SAME, _BEFORE and _AFTER share the value 0x01000000.
  • ArrayMap
    • hashCodeCache is never invalidated, and it isn't Map-contract compatible.
    • equals doesn't compare sizes, and it tests the entry, not the value, for null.
  • OneToOneMap.put: can leave stale reverse entries.
  • BoundedPriorityQueue.add: tests compared == 1 where it should test > 0. A queue made with the one-argument constructor throws a NullPointerException once it's full.
  • IntervalTree
    • balance() throws a NullPointerException on an empty tree.
    • remove can miss an equal interval that rotations left in the right subtree.
    • getNonOverlappingMaxScore (doc) depends on input order and can skip an item whose end key is already present.
  • StringParsingTask.unread(): decrements even after a read at EOF that didn't advance.
  • AcronymMatcher.isFancyAcronymImpl: a repeated letter can match the same token twice.
  • MapFactory
    • TreeMapFactory.setMap has its comparator check inverted.
    • TreeMapFactory.newSet(Collection) ignores the comparator.
    • ArrayMapFactory.newSet(Collection) ignores init.
  • CoreMaps.asMap: remove leaves the key in references.
  • ArrayStringFilter: equals and hashCode disagree when there are duplicate words, and hashCode ignores the mode.
  • RegexStringFilter: equals and hashCode use Pattern identity.
  • Filters.NegatedFilter.toString: prints NOT(...) even when the filter isn't negated.
  • VariableStrings.setVar / setVars: the map is updated before the conflict check, so state is left half-applied when the exception is thrown.
  • Comparators.reverse: -compare(...) doesn't reverse Integer.MIN_VALUE.
  • FastDisjointSet.union: doesn't check whether the roots are the same, so ranks get inflated. The results are still correct.
  • ProcessProtobufRequest: matches -multiple ignoring case but filters it case-sensitively.

I/O and threading

  • SystemUtils.runShellCommand: reads stdout fully before stderr, which can deadlock. It never calls waitFor(). The String cmd overloads don't split the command into arguments.
  • ByteStreamGobbler.run: never flushes the BufferedOutputStream.
  • StreamGobbler.shouldRun: not volatile, so kill() may never be seen.
  • Redwood.FileHandler: if the file can't be opened, every later print throws a NullPointerException. Redwood.Util.fail(Object) (doc) throws for non-String, non-Throwable arguments where every other branch returns.
  • RerouteChannel: writes into the incoming Record's internal channels array.
  • CollectionUtils.loadCollection (both versions) and XMLUtils.readDocumentFromFile: leak their readers when an exception is thrown. readDocumentFromFile also reads with the platform default encoding.
  • XMLUtils
    • The sibling loops take n+1 siblings on each side, not n.
    • getXmlParser rejects any DOCTYPE, despite its "ignores DTDs" doc.
    • The pattern &.+?; also eats a bare & up to the next ;.
    • markLineBreaks throws a NullPointerException on an unterminated trailing tag.
  • ConfusionMatrix GUI: compares labels with ==, and sets the font on g after g2d was created from it.
  • ArrayHeap.verify(): calls System.exit(0) on a violation, which exits with a success status.