{"record":{"id":"8739ab080c330de4","repo":"pentaho/pentaho-kettle","slug":"unknown-xml-event","errorCode":null,"errorMessage":"Unknown XML event: ","messagePattern":"Unknown XML event: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/xml/XMLFormatter.java","lineNumber":143,"sourceCode":"            cdata.append( rd.getText() );\n            wasSomething = true;\n            break;\n          case XMLStreamConstants.COMMENT:\n            if ( !whitespacesOnly( str ) ) {\n              wr.writeCharacters( str.toString() );\n            } else if ( wasSomething ) {\n              wr.writeCharacters( \"\\n\" + prefix );\n            }\n            str.setLength( 0 );\n            wr.writeComment( rd.getText() );\n            wasSomething = true;\n            break;\n          case XMLStreamConstants.END_DOCUMENT:\n            wr.writeCharacters( \"\\n\" );\n            wr.writeEndDocument();\n            break;\n          default:\n            throw new RuntimeException( \"Unknown XML event: \" + event );\n        }\n      }\n\n      wr.flush();\n\n      return result.toString();\n    } catch ( XMLStreamException ex ) {\n      throw new RuntimeException( ex );\n    } finally {\n      try {\n        if ( wr != null ) {\n          wr.close();\n        }\n      } catch ( Exception ex ) {\n      }\n      try {\n        if ( rd != null ) {\n          rd.close();","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/xml/XMLFormatter.java#L125-L161","documentation":"XMLFormatter.format() walks an XML stream (StaX) and throws this RuntimeException in its default case when it encounters an XML stream event type it does not explicitly handle (only start/end element, characters, etc. are supported).","triggerScenarios":"Formatting XML whose stream emits unhandled event types, e.g. PROCESSING_INSTRUCTION, DTD, ENTITY_REFERENCE, CDATA variants or COMMENT depending on handled cases.","commonSituations":"Formatting documents with DOCTYPE declarations, processing instructions (<?xml-stylesheet?>), comments or entity references; different StaX implementations surfacing more event types.","solutions":["Inspect the numeric event value in the message and map it to an XMLStreamConstants constant","Add a case for the missing event type (e.g. XMLStreamConstants.COMMENT) in the switch to ignore or copy it","Strip comments/processing instructions/doctype from the XML before formatting","Set the input factory to coalesce/replacement-safe properties (e.g. P_LAZY? coalescing true, replacing entity references) so exotic events are not emitted","Wrap format() in a try-catch if formatting is best-effort"],"exampleFix":"// before\ndefault:\n  throw new RuntimeException( \"Unknown XML event: \" + event );\n// after\ncase XMLStreamConstants.PROCESSING_INSTRUCTION:\ncase XMLStreamConstants.COMMENT:\ncase XMLStreamConstants.DTD:\n  break; // skip unhandled events\ndefault:\n  throw new RuntimeException( \"Unknown XML event: \" + event );","handlingStrategy":"try-catch","validationCode":"// Detect constructs that map to unhandled events before formatting:\nboolean risky = xml.contains( \"<!DOCTYPE\" ) || xml.contains( \"<?\" ) || xml.contains( \"<!--\" );","typeGuard":null,"tryCatchPattern":"try {\n  result = XMLFormatter.format( xml );\n} catch ( RuntimeException e ) {\n  if ( e.getMessage().startsWith( \"Unknown XML event:\" ) ) {\n    // handle/strip the offending construct and retry, or skip formatting\n  } else {\n    throw e;\n  }\n}","preventionTips":["Strip DOCTYPE/comments/processing instructions before formatting","Keep the input XML plain (elements + text) when possible","Pin a known StaX implementation to keep event streams predictable","Add cases for extra XMLStreamConstants values when extending format()"],"tags":["xml","parsing","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}