Skip to content

Fix NPE in Matrix constructors - #743

Open
LonelyMidoriya wants to merge 2 commits into
integrationfrom
matrix
Open

Fix NPE in Matrix constructors#743
LonelyMidoriya wants to merge 2 commits into
integrationfrom
matrix

Conversation

@LonelyMidoriya

@LonelyMidoriya LonelyMidoriya commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of invalid or incomplete matrix data.
    • Documents with null or non-numeric matrix values now fall back safely to the identity matrix instead of producing unreliable results.
    • Valid matrix values continue to be processed normally.

@LonelyMidoriya LonelyMidoriya self-assigned this Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@LonelyMidoriya, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 90969b89-ab75-4f15-add1-9a23c992202b

📥 Commits

Reviewing files that changed from the base of the PR and between 66b57ef and c5a4397.

📒 Files selected for processing (1)
  • wcag-validation/src/main/java/org/verapdf/gf/model/factory/chunks/Matrix.java
📝 Walkthrough

Walkthrough

Matrix constructors now validate all six inputs. Invalid or non-real values trigger a warning and reset the matrix to the identity matrix.

Changes

Matrix validation

Layer / File(s) Summary
Constructor validation
wcag-validation/src/main/java/org/verapdf/gf/model/factory/chunks/Matrix.java
The constructors iterate over all six inputs, convert valid values, and reset invalid inputs to the identity matrix while logging a warning.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: maximplusov

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing null pointer exceptions in Matrix constructors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch matrix

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Consider extracting the duplicated validation loop.

The Matrix(COSArray array) and Matrix(List<COSBase> arguments) constructors share nearly identical validation logic, differing only in the element accessor (array.at(i) vs arguments.get(i)) and the log message's source description. Extract a shared private helper that takes an IntFunction<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

📥 Commits

Reviewing files that changed from the base of the PR and between 4dea032 and 66b57ef.

📒 Files selected for processing (1)
  • wcag-validation/src/main/java/org/verapdf/gf/model/factory/chunks/Matrix.java

Comment thread wcag-validation/src/main/java/org/verapdf/gf/model/factory/chunks/Matrix.java Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant