{"record":{"id":"4f2ff79ab496d110","repo":"pentaho/pentaho-kettle","slug":"unable-to-encode-string-in-encoding-const-xml-encoding","errorCode":null,"errorMessage":"Unable to encode String in encoding [\" + Const.XML_ENCODING + \"]","messagePattern":"Unable to encode String in encoding \\[\" \\+ Const\\.XML_ENCODING \\+ \"\\]","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"ui/src/main/java/org/pentaho/di/core/dnd/DragAndDropContainer.java","lineNumber":148,"sourceCode":"  public String getXML() {\n    try {\n      StringBuilder xml = new StringBuilder( 100 );\n\n      xml.append( XMLHandler.getXMLHeader() ); // UFT-8 XML header\n      xml.append( XMLHandler.openTag( XML_TAG ) ).append( Const.CR );\n\n      if ( id != null ) {\n        xml.append( \"  \" ).append( XMLHandler.addTagValue( \"ID\", id ) );\n      }\n      xml.append( \"  \" ).append( XMLHandler.addTagValue( \"DragType\", getTypeCode() ) );\n      xml.append( \"  \" ).append(\n        XMLHandler\n          .addTagValue( \"Data\", new String( Base64.encodeBase64( data.getBytes( Const.XML_ENCODING ) ) ) ) );\n      xml.append( XMLHandler.closeTag( XML_TAG ) ).append( Const.CR );\n\n      return xml.toString();\n    } catch ( UnsupportedEncodingException e ) {\n      throw new RuntimeException( \"Unable to encode String in encoding [\" + Const.XML_ENCODING + \"]\", e );\n    }\n  }\n\n  /**\n   * Construct a Drag and drop container from an XML String\n   *\n   * @param xml\n   *          The XML string to convert from\n   */\n  public DragAndDropContainer( String xml ) throws KettleXMLException {\n    try {\n      Document doc = XMLHandler.loadXMLString( xml );\n      Node dnd = XMLHandler.getSubNode( doc, XML_TAG );\n\n      id = XMLHandler.getTagValue( dnd, \"ID\" );\n      type = getType( XMLHandler.getTagValue( dnd, \"DragType\" ) );\n      data =\n        new String( Base64.decodeBase64( XMLHandler.getTagValue( dnd, \"Data\" ).getBytes() ), Const.XML_ENCODING );","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/ui/src/main/java/org/pentaho/di/core/dnd/DragAndDropContainer.java#L130-L166","documentation":"DragAndDropContainer.getXML serializes drag-and-drop payload bytes as Base64 using Const.XML_ENCODING; because that charset is a compile-time constant that Java must support, UnsupportedEncodingException is treated as an unrecoverable condition and rethrown as a RuntimeException. In practice this should never occur unless the JVM lacks the standard charset.","triggerScenarios":"getXML (public) is called to serialize the container for drag-and-drop transfer; data.getBytes(Const.XML_ENCODING) throws UnsupportedEncodingException — essentially only on a broken/limited JVM charset configuration (e.g. unusual charset provider setup).","commonSituations":"Custom JVM builds without standard encodings, exotic -Dfile.encoding/charset provider misconfiguration, instrumentation environments that intercept charset lookups.","solutions":["Restore the JVM's charset configuration (remove unusual -Dfile.encoding or charset provider overrides) and restart the client.","Use a standard, unmodified JDK/JRE distribution for Spoon/PDI.","Verify Const.XML_ENCODING ('UTF-8') is supported: Charset.forName(\"UTF-8\") in the same JVM.","Report as a bug if it occurs on a stock JVM — the code could safely use StandardCharsets.UTF_8."],"exampleFix":"// before\nnew String(Base64.encodeBase64(data.getBytes(Const.XML_ENCODING)))\n// after (no checked exception possible)\nnew String(Base64.encodeBase64(data.getBytes(StandardCharsets.UTF_8)))","handlingStrategy":"try-catch","validationCode":"// confirm the JVM supports the XML encoding before operations\nif (!Charset.isSupported(Const.XML_ENCODING)) {\n  throw new IllegalStateException(\"JVM does not support \" + Const.XML_ENCODING);\n}","typeGuard":null,"tryCatchPattern":"try { String xml = container.getXML(); }\ncatch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Unable to encode String\")) {\n    log.error(\"Charset broken in JVM: reinstall/standard JDK\");\n  }\n  throw e;\n}","preventionTips":["Run Spoon/PDI on a stock JDK without charset provider overrides.","Avoid custom -Dfile.encoding experiments in production clients.","Add a startup charset sanity check (Charset.isSupported(\"UTF-8\"))."],"tags":["encoding","runtime-exception","serialization"],"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"}