Repository navigation
Java: reject adding the same Constraint twice to a Problem - #2228
akhil9tiet wants to merge 1 commit into
Conversation
Signed-off-by: Akhil Gupta <akhilgupta.swe@gmail.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Reject an already-added constraint java/cuopt/src/main/java/com/nvidia/cuopt/mathematicaloptimization/Problem.java |
addConstraint throws IllegalArgumentException when the constraint is already in the problem. The check runs before ownership validation or changes to the constraint’s name and index. |
Priority:
Estimated code review effort: 2 (Simple) | ~5 minutes
Change: Bug fix · Severity of issue fixed: Low
Possibly related PRs
- NVIDIA/cuopt#2226: This PR rejects the same constraint object on a second call to
Problem.addConstraint. - NVIDIA/cuopt#2219: This PR adds a test for adding the same constraint twice.
Suggested reviewers: iroy30
Merge Risk: 
Minimal · up to dcf47
-
The duplicate-constraint behavior matches the requested contract, with no identified merge-blocking risk.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Issue
#2224requiresProblem.addConstraintto reject the sameConstraintobject twice withIllegalArgumentExceptionand keep the constraint count at one. The change checksconstraints.contains(constraint)before ownership validation, renaming, and reindexing.Constrainthas noequalsoverride, so the check is identity-based. The rejected call does not modify the list.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
Closing per maintainer request — continuing on #2226, which now carries the test and the formatting fix. |
Fixes #2224
The second call overwrites the constraint's index and the list holds it twice, so the problem has an inconsistent constraint list. This change adds a guard in addConstraint that throws IllegalArgumentException when the constraint is already in the list, checked before any rename/reindex so a rejected duplicate leaves the list untouched. Constraint has no equals override so the check is identity-based.