You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: add missing type checks to parameter validators
Add instanceof type checks to 3 validators that only checked parameter
existence but not type (filter in Update/Delete, keys/indexName in
DropIndex). Also add options type validation to the 5 validators for
operations that support options (Insert, Update, CreateIndex, CreateView,
RenameCollection).
This closes the remaining ClassCastException gaps in MongoOperation
getters — since validate() runs at load time via the TemplatePayload
contract, the @SuppressWarnings("unchecked") casts are now effectively
safe.
Resolves ANALYSIS.md issue #4.
**Original issue:**`modifyCollection` used `OperationValidator.NO_OP` in `MongoOperationType`, so none of its three parameters (`validator`, `validationLevel`, `validationAction`) were validated. A user could pass `validationLevel: "banana"` and it would pass validation, only to fail at MongoDB runtime.
44
44
**Resolution:**`ModifyCollectionParametersValidator` now validates at load time: requires at least one recognized parameter, checks `validator` is a document (Map), checks `validationLevel` is one of `off`/`strict`/`moderate`, and checks `validationAction` is one of `error`/`warn`. Multiple errors accumulate. Wired into `MongoOperationType.MODIFY_COLLECTION` replacing the `NO_OP` validator.
45
45
46
-
### #4 - HIGH: Type-unsafe parameter extraction throughout MongoOperation
47
-
**File:**`MongoOperation.java:46-115`
48
-
**Impact:** Every parameter getter uses `@SuppressWarnings("unchecked")` with raw casts from `Map<String, Object>`. Examples:
49
-
-`getDocuments()` (line 47): `(List<Map<String, Object>>) parameters.get("documents")` - throws `ClassCastException` if YAML has `documents: "not a list"`
50
-
-`getKeys()` (line 54): `(Map<String, Object>) parameters.get("keys")` - same issue
51
-
-`getFilter()` (line 68): same pattern
52
-
-`getUpdate()` (line 108): same pattern
53
-
54
-
While the validator catches some of these cases, the validator runs only on the apply path (see #1). Additionally, `getOptions()` (line 62) is called by operators but NEVER validated by `MongoOperationValidator` - an unknown key in `options` produces no error.
55
-
**Risk:**`ClassCastException` at runtime with unhelpful stack trace instead of a clear validation error.
56
-
**Fix:** Either add type checking in the getters (return Optional/throw descriptive error), or ensure validation is exhaustive for all parameter access paths.
46
+
### #4 - ~~HIGH: Type-unsafe parameter extraction throughout MongoOperation~~ RESOLVED
47
+
**Status:** Fixed by adding type checks to all parameter validators.
48
+
**Original issue:** Every parameter getter in `MongoOperation` uses `@SuppressWarnings("unchecked")` raw casts from `Map<String, Object>`, risking `ClassCastException` at runtime if YAML contained wrong-typed values. Additionally, `getOptions()` was called by operators but never validated.
49
+
**Resolution:** All parameter validators now include `instanceof` type checks that run at load time via `MongoOperation.validate()` (the `TemplatePayload` contract). Specifically: `UpdateParametersValidator` and `DeleteParametersValidator` check that `filter` is a `Map`; `DropIndexParametersValidator` checks that `keys` is a `Map` and `indexName` is a `String`; and the 5 validators for operations that support options (`InsertParametersValidator`, `UpdateParametersValidator`, `CreateIndexParametersValidator`, `CreateViewParametersValidator`, `RenameCollectionParametersValidator`) check that `options` is a `Map` when present. Since the framework guarantees `validate()` runs before any operator executes, the `@SuppressWarnings("unchecked")` casts in getters are now effectively safe — they can never be reached with wrong-typed data.
57
50
58
51
### #5 - HIGH: CreateIndexOperator claims `transactional=true` but ignores the session
0 commit comments