Fix NPE in Matrix constructors - #743
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesMatrix validation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
wcag-validation/src/main/java/org/verapdf/gf/model/factory/chunks/Matrix.java (1)
52-80: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider extracting the duplicated validation loop.
The
Matrix(COSArray array)andMatrix(List<COSBase> arguments)constructors share nearly identical validation logic, differing only in the element accessor (array.at(i)vsarguments.get(i)) and the log message's source description. Extract a shared private helper that takes anIntFunction<COSObject>(or similar) to reduce duplication.♻️ Proposed refactor
public Matrix(COSArray array) { matrixArray = new double[SIZE]; - for (int i = 0; i < SIZE; i++) { - COSObject arg = array.at(i); - Double d = (arg != null) ? arg.getReal() : null; - if (d == null) { - matrixArray = new double[] {1, 0, 0, 1, 0, 0}; - LOGGER.log(Level.WARNING,"Null real value for matrix argument at index {0} in COSArray. " + - "Defaulting to matrix [1,0,0,1,0,0].", i); - return; - } - matrixArray[i] = d; - } + populateFromValues(i -> array.at(i), "COSArray"); } public Matrix(List<COSBase> arguments) { matrixArray = new double[SIZE]; - for (int i = 0; i < SIZE; i++) { - COSBase arg = arguments.get(i); - Double d = (arg != null) ? arg.getReal() : null; - if (d == null) { - matrixArray = new double[] {1, 0, 0, 1, 0, 0}; - LOGGER.log(Level.WARNING,"Null real value for matrix argument at index {0} in List of arguments. " + - "Defaulting to matrix [1,0,0,1,0,0].", i); - return; - } - matrixArray[i] = d; - } + populateFromValues(i -> arguments.get(i) != null ? arguments.get(i).getReal() : null, "List of arguments"); +} + +private void populateFromValues(java.util.function.IntFunction<Double> valueAt, String source) { + for (int i = 0; i < SIZE; i++) { + Double d = valueAt.apply(i); + if (d == null) { + matrixArray = new double[] {1, 0, 0, 1, 0, 0}; + LOGGER.log(Level.WARNING, "Null real value for matrix argument at index {0} in " + source + ". " + + "Defaulting to matrix [1,0,0,1,0,0].", i); + return; + } + matrixArray[i] = d; + } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@wcag-validation/src/main/java/org/verapdf/gf/model/factory/chunks/Matrix.java` around lines 52 - 80, Extract the duplicated matrix-element validation from the Matrix(COSArray array) and Matrix(List<COSBase> arguments) constructors into a private helper that accepts an element accessor and source description. Have each constructor delegate to this helper, preserving the existing default identity matrix, warning behavior, and COSArray/List access semantics.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@wcag-validation/src/main/java/org/verapdf/gf/model/factory/chunks/Matrix.java`:
- Around line 59-60: Update the warning log calls in Matrix to use
java.util.logging MessageFormat placeholders, replacing each `{}` in the
messages at the null real-value handling sites with `{0}` while continuing to
pass the argument index `i` as the formatting parameter.
---
Nitpick comments:
In
`@wcag-validation/src/main/java/org/verapdf/gf/model/factory/chunks/Matrix.java`:
- Around line 52-80: Extract the duplicated matrix-element validation from the
Matrix(COSArray array) and Matrix(List<COSBase> arguments) constructors into a
private helper that accepts an element accessor and source description. Have
each constructor delegate to this helper, preserving the existing default
identity matrix, warning behavior, and COSArray/List access semantics.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7286c19c-fafc-4112-89a3-e72b366fb240
📒 Files selected for processing (1)
wcag-validation/src/main/java/org/verapdf/gf/model/factory/chunks/Matrix.java
Summary by CodeRabbit