insaf021 opened a new pull request, #347:
URL: https://github.com/apache/commons-math/pull/347
Observed on master with the default formats:
new RealMatrixFormat().parse("{{1,2},{}}") ->
Array2DRowRealMatrix{{1.0,2.0}}
new RealMatrixFormat().parse("{{1},{2}") -> null
new RealVectorFormat().parse("{1;2") -> null
Two separate paths let malformed text through.
`parse(String)` is documented to throw MathParseException, but both classes
detect failure with `parsePosition.getIndex() == 0`. The `parseFixedstring`
failure paths in `parse(String, ParsePosition)` leave the index past whatever
was consumed, so the caller gets null instead of the exception. ComplexFormat
already tests `result == null`; the same test is now used here.
In RealMatrixFormat, a row that has its prefix but no component is treated
as the end of the matrix, and the unconsumed `}` is then matched as the matrix
suffix. The empty row disappears and the result has the wrong dimensions. Once
a row has been opened after earlier rows it now needs a component, so it fails
like any other invalid component. Formats with an empty row prefix have no
opened row to reject and still accept a closing row separator; a test pins that.
Regression tests in RealMatrixFormatAbstractTest and
RealVectorFormatAbstractTest fail without the patch. `mvn clean verify` on
commons-math-legacy and its dependencies passes on JDK 17 (3278 tests in
legacy), as does checkstyle:check. This is separate from #338, which fixed the
CompositeFormat cursor helpers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]