{"record":{"id":"116fd8510484932e","repo":"pentaho/pentaho-kettle","slug":"unexpected-error-encoding-job-result-as-xml","errorCode":null,"errorMessage":"Unexpected error encoding job result as XML","messagePattern":"Unexpected error encoding job result as XML","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"core/src/main/java/org/pentaho/di/core/Result.java","lineNumber":616,"sourceCode":"\n      xml.append( XMLHandler.openTag( XML_ROWS_TAG ) );\n      boolean firstRow = true;\n      RowMetaInterface rowMeta = null;\n      for ( RowMetaAndData row : rows ) {\n        if ( firstRow ) {\n          firstRow = false;\n          rowMeta = row.getRowMeta();\n          xml.append( rowMeta.getMetaXML() );\n        }\n        xml.append( rowMeta.getDataXML( row.getData() ) );\n      }\n      xml.append( XMLHandler.closeTag( XML_ROWS_TAG ) );\n\n      xml.append( XMLHandler.closeTag( XML_TAG ) );\n\n      return xml.toString();\n    } catch ( IOException e ) {\n      throw new RuntimeException( \"Unexpected error encoding job result as XML\", e );\n    }\n  }\n\n  private StringBuilder setBasicXmlAttrs( StringBuilder xml ) {\n    // First the metrics...\n    //\n    xml.append( XMLHandler.addTagValue( \"lines_input\", nrLinesInput ) );\n    xml.append( XMLHandler.addTagValue( \"lines_output\", nrLinesOutput ) );\n    xml.append( XMLHandler.addTagValue( \"lines_read\", nrLinesRead ) );\n    xml.append( XMLHandler.addTagValue( \"lines_written\", nrLinesWritten ) );\n    xml.append( XMLHandler.addTagValue( \"lines_updated\", nrLinesUpdated ) );\n    xml.append( XMLHandler.addTagValue( \"lines_rejected\", nrLinesRejected ) );\n    xml.append( XMLHandler.addTagValue( \"lines_deleted\", nrLinesDeleted ) );\n    xml.append( XMLHandler.addTagValue( \"nr_errors\", nrErrors ) );\n    xml.append( XMLHandler.addTagValue( \"nr_files_retrieved\", nrFilesRetrieved ) );\n    xml.append( XMLHandler.addTagValue( \"entry_nr\", entryNr ) );\n\n    // The high level results...","sourceCodeStart":598,"sourceCodeEnd":634,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/Result.java#L598-L634","documentation":"Result.getXML() serializes job/transformation execution results (rows, files, metrics) to XML using XMLHandler, which can throw IOException from Writer/StringWriter usage. The library wraps any such IOException in a RuntimeException because XML building in memory is not expected to fail.","triggerScenarios":"Calling getXML() when the underlying serialization raises IOException — practically rare, but possible via an XMLHandler path performing unexpected I/O or an environment failure while building the string buffer.","commonSituations":"Custom Result subclasses or patched XMLHandler doing real I/O during serialization, JVM-level resource issues, or passing unusually large result sets triggering underlying stream problems.","solutions":["Inspect the wrapped cause (getCause()) to find the actual IOException source","Review custom XMLHandler implementations or subclasses for real I/O in serialization","Retry serialization after resolving the environmental I/O problem","If results are huge, reduce streamed result rows before serializing"],"exampleFix":"// before\nString xml = result.getXML();\n// after\nString xml;\ntry {\n  xml = result.getXML();\n} catch (RuntimeException e) {\n  log.error(\"XML serialization of Result failed\", e.getCause());\n  xml = \"\";\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  String xml = result.getXML();\n} catch (RuntimeException e) {\n  // unwrap IOException via e.getCause() and log; degrade gracefully\n}","preventionTips":["Avoid custom XMLHandler/Writer code with real I/O inside serialization paths","Log and inspect getCause() when it occurs to find the real I/O source","Keep result rows within reasonable size limits"],"tags":["xml","serialization","unexpected"],"backgroundTag":"json-marshal-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}