{"record":{"id":"d67043280bffdf60","repo":"FasterXML/jackson-databind","slug":"trying-to-resolve-a-forward-reference-with-id-d67043","errorCode":null,"errorMessage":"Trying to resolve a forward reference with id [{}] that wasn't previously seen as unresolved.","messagePattern":"Trying to resolve a forward reference with id \\[(.+?)\\] that wasn't previously seen as unresolved\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/tools/jackson/databind/deser/impl/ObjectIdReferenceProperty.java","lineNumber":135,"sourceCode":"\n    public final static class PropertyReferring extends Referring {\n        private final ObjectIdReferenceProperty _parent;\n        public final Object _pojo;\n\n        public PropertyReferring(ObjectIdReferenceProperty parent,\n                UnresolvedForwardReference ref, Class<?> type, Object ob)\n        {\n            super(ref, type);\n            _parent = parent;\n            _pojo = ob;\n        }\n\n        @Override\n        public void handleResolvedForwardReference(DeserializationContext ctxt,\n                Object id, Object value) throws JacksonException\n        {\n            if (!hasId(id)) {\n                throw new IllegalArgumentException(\"Trying to resolve a forward reference with id [\" + id\n                        + \"] that wasn't previously seen as unresolved.\");\n            }\n            // [databind#1496]: forward ref resolved, remove from pending set\n            ctxt.removePendingForwardRef(_pojo);\n            _parent.set(ctxt, _pojo, value);\n        }\n    }\n}\n","sourceCodeStart":117,"sourceCodeEnd":144,"githubUrl":"https://github.com/FasterXML/jackson-databind/blob/a50c7d2a1d57234ac4adf70dbd88ac90db6436e4/src/main/java/tools/jackson/databind/deser/impl/ObjectIdReferenceProperty.java#L117-L144","documentation":"Thrown by ObjectIdReferenceProperty.PropertyReferring.handleResolvedForwardReference when attempting to resolve a forward reference by an id that was never registered as pending. The PropertyReferring object (created for properties annotated with @JsonObjectIdReferenceProperty) checks hasId(id) and rejects ids it doesn't recognize. This indicates a mismatch between the ids being resolved and those previously tracked during deserialization.","triggerScenarios":"A property using @JsonIdentityReference (or @JsonIdentityInfo on a property) where the resolveForwardReference API is called with an id not previously encountered. Programmatic forward-reference resolution out of order. JSON with object id references whose ids don't match any pending unresolved references.","commonSituations":"Using @JsonIdentityInfo with a property-level reference where the JSON stream contains ids that were never registered. Mixing manual and automatic forward-reference resolution. Deserialization order changes causing id mismatches after a refactor.","solutions":["Ensure forward references are resolved in the same order they were encountered during deserialization.","Verify the @JsonIdentityInfo generator produces ids consistent with what appears in the JSON.","If resolving manually, only pass ids that were returned by the framework's unresolved reference tracking.","Check for truncated or malformed JSON that might introduce spurious id references."],"exampleFix":"// before: resolving id \"99\" that was never seen\nroid.handleResolvedForwardReference(ctxt, \"99\", value);\n// after: only resolve ids that were registered\nif (roid.hasId(id)) {\n    roid.handleResolvedForwardReference(ctxt, id, value);\n}","handlingStrategy":"validation","validationCode":"// Before resolving, check hasId\nif (referring.hasId(id)) {\n    referring.handleResolvedForwardReference(ctxt, id, value);\n}","typeGuard":"if (roid.hasId(id)) {\n    roid.handleResolvedForwardReference(ctxt, id, value);\n}","tryCatchPattern":"try {\n    referring.handleResolvedForwardReference(ctxt, id, value);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"wasn't previously seen\")) {\n        logger.warn(\"Unknown forward ref id: {}\", id);\n    } else { throw e; }\n}","preventionTips":["Only resolve ids that were previously registered as unresolved.","Keep @JsonIdentityInfo configuration consistent.","Validate id completeness before resolution."],"tags":["jackson","deserialization","forward-reference","object-id","identity-reference"],"analyzedSha":"a50c7d2a1d57234ac4adf70dbd88ac90db6436e4","analyzedAt":"2026-08-06T20:31:51.404Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}