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 computesf(g(x))instead ofg(f(x)). The raw type hides this from the compiler. - DeltaCollectionValuedMap.remove / clear: both store a plain
Objectmarker cast toCollection, soremovealways throwsClassCastException.get,addandremoveMappingfail 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, andusedSwapis 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.byteArrToDoubleArrcasts to(long)first and gets this right.shortArrToByteArrwrites 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, ...)ignoresoff.- The
*ArrToByteArrsubrange versions size their output withs.lengthinstead oflength. - The 5-argument
byteArrToUStringArrandbyteArrToAStringArrreads[i]where they should reads[i + pos]. readDoubleArrandreadFloatArruse a singleread(), notreadFully.
- The char readers don't mask the low byte with
- TwoDimensionalSet.add (doc): returns true when the pair was already present, the opposite of
Set.add.addAllandaddAllKeysinherit this. - TwoDimensionalSet.remove (doc): unboxes a null
Booleanwhen the pair is absent and throws a NullPointerException.removeAllfails the same way. - IterableIterator(Stream) (doc):
iterator()andspliterator()run a second terminal operation on the stream and throwIllegalStateException, so a for-each over one fails. - FixedPrioritiesPriorityQueue:
iterator()goes throughtoSortedList(), which drains the queue. Any iteration, including inheritedAbstractSetmethods, empties it.getPriorityon a missing key throws; the interface says it returns-Infinity. - HashIndex.loadFromReader:
continueskips thereadLine(), so a line with no=, or ending in=, causes an infinite loop. - MetaClass.castWithoutKnowingType (doc):
A && !B || Cparses as(A && !B) || C. Any value containing a space skips every type, String included, and returns null. - ArgumentParser: a required option that has
altnames 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, sojoin()hangs. - SystemUtils.ProcessOutputStream.close(): joins
StreamGobblerthreads that only stop afterkill(), and nothing callskill(). It appears to hang forever.
Wrong results in edge cases
- UnorderedPair.compareTo
other1/other2are taken fromthis, not fromother.- The second-element branch returns
c1, which is 0 at that point, instead ofc2.
- DeltaIndex.objectsList: tests
result.size() > backingIndexSizeon the still-emptyresult. It should usebackingIndex.size(). - DeltaMap.clear(): keys that were only added through
putsurvive 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 fromsecond. - StringUtils
nthIndex(doc) never counts a match at position 0.toAsciimaps Ì Í Î Ï to "F".toAsciitestsc <= 0x2014where it should test0x2013, so all of Greek, Cyrillic, Arabic and CJK become "-".resolveVarssupports only${VAR}, not the documented$VAR. Its replacement isn't passed throughquoteReplacement, so a value containing$or\breaks it.toTitleCaseandisAllUpperCasecast code points tochar, which corrupts non-BMP characters.searchAndReplace(doc) escapes only. [ ] \.makeTextTablemisaligns the header row whenrowLabelsis 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)usesarray[0].getClass()for the new array.getSubListIndexloops forever whentofindis empty.
- Interval
checkMultipleBitSetalways returns false, soREL_FLAGS_INTERVAL_FUZZYis never set.REL_FLAGS_INTERVAL_ALMOST_SAME,_BEFOREand_AFTERshare the value0x01000000.
- ArrayMap
hashCodeCacheis never invalidated, and it isn'tMap-contract compatible.equalsdoesn't compare sizes, and it tests the entry, not the value, for null.
- OneToOneMap.put: can leave stale reverse entries.
- BoundedPriorityQueue.add: tests
compared == 1where 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.removecan 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.setMaphas its comparator check inverted.TreeMapFactory.newSet(Collection)ignores the comparator.ArrayMapFactory.newSet(Collection)ignoresinit.
- CoreMaps.asMap:
removeleaves the key inreferences. - ArrayStringFilter:
equalsandhashCodedisagree when there are duplicate words, andhashCodeignores the mode. - RegexStringFilter:
equalsandhashCodeusePatternidentity. - 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 reverseInteger.MIN_VALUE. - FastDisjointSet.union: doesn't check whether the roots are the same, so ranks get inflated. The results are still correct.
- ProcessProtobufRequest: matches
-multipleignoring case but filters it case-sensitively.
I/O and threading
- SystemUtils.runShellCommand: reads stdout fully before stderr, which can deadlock. It never calls
waitFor(). TheString cmdoverloads don't split the command into arguments. - ByteStreamGobbler.run: never flushes the
BufferedOutputStream. - StreamGobbler.shouldRun: not
volatile, sokill()may never be seen. - Redwood.FileHandler: if the file can't be opened, every later
printthrows 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.
readDocumentFromFilealso reads with the platform default encoding. - XMLUtils
- The sibling loops take n+1 siblings on each side, not n.
getXmlParserrejects any DOCTYPE, despite its "ignores DTDs" doc.- The pattern
&.+?;also eats a bare&up to the next;. markLineBreaksthrows a NullPointerException on an unterminated trailing tag.
- ConfusionMatrix GUI: compares labels with
==, and sets the font ongafterg2dwas created from it. - ArrayHeap.verify(): calls
System.exit(0)on a violation, which exits with a success status.
Source: stanfordnlp/CoreNLP