{"record":{"id":"954c1ee2f3025b4e","repo":"apache/beam","slug":"either-elementuri-or-elementcontents-should-be-non-null","errorCode":null,"errorMessage":"Either elementURI or elementContents should be non-null","messagePattern":"Either elementURI or elementContents should be non-null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/AnnotateVideoFn.java","lineNumber":91,"sourceCode":"   * Call the Video Intelligence Cloud AI service and return annotation results.\n   *\n   * @param elementURI This or elementContents is required. GCS address of video to be annotated\n   * @param elementContents this or elementURI is required. Hex-encoded contents of video to be\n   *     annotated\n   * @param videoContext Optional context for video annotation.\n   * @return\n   */\n  List<VideoAnnotationResults> getVideoAnnotationResults(\n      String elementURI, ByteString elementContents, VideoContext videoContext)\n      throws InterruptedException, ExecutionException {\n    AnnotateVideoRequest.Builder requestBuilder =\n        AnnotateVideoRequest.newBuilder().addAllFeatures(featureList);\n    if (elementURI != null) {\n      requestBuilder.setInputUri(elementURI);\n    } else if (elementContents != null) {\n      requestBuilder.setInputContent(elementContents);\n    } else {\n      throw new IllegalArgumentException(\"Either elementURI or elementContents should be non-null\");\n    }\n    if (videoContext != null) {\n      requestBuilder.setVideoContext(videoContext);\n    }\n    AnnotateVideoRequest annotateVideoRequest = requestBuilder.build();\n    OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> annotateVideoAsync =\n        videoIntelligenceServiceClient.annotateVideoAsync(annotateVideoRequest);\n    return annotateVideoAsync.get().getAnnotationResultsList();\n  }\n\n  /** Process element implementation required. */\n  @ProcessElement\n  public abstract void processElement(ProcessContext context)\n      throws ExecutionException, InterruptedException;\n}\n","sourceCodeStart":73,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/ml/src/main/java/org/apache/beam/sdk/extensions/ml/AnnotateVideoFn.java#L73-L107","documentation":"getVideoAnnotationResults builds a Google Video Intelligence AnnotateVideoRequest from either a GCS URI or inline bytes. If both elementURI and elementContents are null there is no video source to send, so it throws IllegalArgumentException. Exactly one input source must be present.","triggerScenarios":"Calling getVideoAnnotationResults on an element where neither the GCS URI nor the raw video contents were populated (both null).","commonSituations":"Upstream DoFn/windowing producing elements with missing metadata; a malformed Pub/Sub or file record without a URI; clearing one field while assuming the other is set.","solutions":["Ensure every input element has either a valid GCS URI or non-null contents before processing.","Add an upstream check that rejects/logs elements lacking both fields.","If reading inline bytes, verify the file read succeeded and contents were set on the element.","Pass a correct gs:// URI to the transform's input source."],"exampleFix":"// before\nprocessElement(... ) { result = getVideoAnnotationResults(element.getURI(), element.getContents(), ...); } // both may be null\n// after\nif (element.getURI() == null && element.getContents() == null) { throw new IllegalStateException(\"Element has no video source\"); }\nresult = getVideoAnnotationResults(element.getURI(), element.getContents(), ...);","handlingStrategy":"validation","validationCode":"if (element.getURI() == null && element.getContents() == null) throw new IllegalArgumentException(\"Video element lacks URI and contents\");","typeGuard":null,"tryCatchPattern":"try { getVideoAnnotationResults(uri, contents, ...); } catch (IllegalArgumentException e) { LOG.warn(\"Skipping element without video source\"); return; }","preventionTips":["Validate input elements in a preceding DoFn","Ensure file reads populate contents before processing","Log and dead-letter elements missing sources"],"tags":["java","google-cloud-video-intelligence","apache-beam","input-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}