Error: Improper use? Potential bug? Your feedback is welcome: Contact: basex-talk@mailman.uni-konstanz.de Version: BaseX 9.2 Java: Oracle Corporation, 9.0.1 OS: Windows 10, amd64 Stack Trace: java.lang.NullPointerException at org.basex.query.expr.TypeswitchGroup.equals(TypeswitchGroup.java:173) at java.base/java.util.Objects.equals(Unknown Source) at org.basex.util.Array.equals(Array.java:332) at org.basex.query.expr.Typeswitch.equals(Typeswitch.java:180) at org.basex.query.expr.gflwor.ForLet.equals(ForLet.java:87) at org.basex.query.expr.gflwor.Let.equals(Let.java:125) at java.base/java.util.AbstractList.equals(Unknown Source) at org.basex.query.expr.gflwor.GFLWOR.equals(GFLWOR.java:917) at org.basex.query.expr.Single.equals(Single.java:86) at org.basex.query.expr.TypeCheck.equals(TypeCheck.java:158) at org.basex.query.expr.Switch.opt(Switch.java:124) at org.basex.query.expr.Switch.optimize(Switch.java:65) at org.basex.query.expr.Switch.compile(Switch.java:59) at org.basex.query.expr.List.compile(List.java:42) at org.basex.query.expr.Arr.compile(Arr.java:42) at org.basex.query.expr.constr.CName.compile(CName.java:52) at org.basex.query.expr.constr.CElem.compile(CElem.java:48) at org.basex.query.expr.gflwor.GFLWOR.compile(GFLWOR.java:94) at org.basex.query.func.StaticFunc.comp(StaticFunc.java:69) at org.basex.query.QueryCompiler.compile(QueryCompiler.java:114) at org.basex.query.QueryCompiler.compile(QueryCompiler.java:105) at org.basex.query.QueryContext.compile(QueryContext.java:312) at org.basex.query.QueryProcessor.compile(QueryProcessor.java:79) at org.basex.core.cmd.AQuery.query(AQuery.java:93) at org.basex.core.cmd.XQuery.run(XQuery.java:22) at org.basex.core.Command.run(Command.java:257) at org.basex.core.Command.execute(Command.java:93) at org.basex.gui.GUI.exec(GUI.java:422) at org.basex.gui.GUI.lambda$execute$4(GUI.java:365) at java.base/java.lang.Thread.run(Unknown Source) Compiling: - pre-evaluate map: map { "method": "xml" } - remove type check: xs:string? -> serialize($input_16, map { "method": "xm... - remove type check: declare function local:is-escaped-markup... - inline local:is-escaped-markup#1 - inline $string_28 as xs:string - simplify FLWOR expression: matches(((: xs:string, true :) $input_17... - rewrite > comparison to range comparison: (html:parse($text_9)/*:html/*:body/node(... - pre-evaluate fn:count(items) to xs:integer item: count((html:parse($text_9)/*:html/*:body... -> 1 - rewrite if to fn:error([code[,desc[,object]]]): if(1) then error() else serialize($text_... -> error() - rewrite > comparison to range comparison: (parse-xml($text_9)/node() > 2) -> (parse-xml($text_9)/node() >= 2.00000000... - pre-evaluate fn:count(items) to xs:integer item: count((parse-xml($text_9)/node() >= 2.00... -> 1 - rewrite if to fn:error([code[,desc[,object]]]): if(1) then error() else $text_9 -> error() - rewrite > comparison to integer range comparison: (count($text_9/node()/ancestor-or-self::... - inline local:escape#1 - inline $input_29 - simplify FLWOR expression: serialize($text_9, map { "method": "xml"... - remove type check: item()* -> ($atomCommonAttributes_13, attribute typ... - inline local:test-for-markup#1 - inline $input_30 - simplify FLWOR expression: typeswitch($content_2) case element()* r... - swap operands: if(not($type_3)) then typeswitch($conten... - pre-evaluate closure to function item: function($suffix_7, $ns_8) as item()* { ... -> function($suffix_7, $ns_8) as namespace-... - inline function($suffix_7, $ns_8) as namespace-... - inline $suffix_40 - inline $ns_41 - simplify FLWOR expression: namespace { $suffix_39 } { ($ns_38) } - pre-evaluate fn:true() to xs:boolean item: true() - inline local:atomPlainTextConstruct#2 - remove type check: $html_43 as xs:boolean? - inline $text_42 - inline $html_43 - simplify FLWOR expression: ((: text(), true :) let $txt_44 := types... - pre-evaluate fn:false() to xs:boolean item: false() - inline local:atomPlainTextConstruct#2 - remove type check: $html_46 as xs:boolean? - inline $text_45 - inline $html_46 - simplify FLWOR expression: ((: text(), true :) let $txt_47 := types... - inline local:atomXHTMLTextConstruct#2 - remove type check: $atomCommonAttributes_49 as attribute()* - inline $text_48 - inline $atomCommonAttributes_49 - remove () from expression list - simplify FLWOR expression: (attribute type { ("xhtml") }, element d... - inline local:atomXHTMLTextConstruct#2 - remove type check: $atomCommonAttributes_51 as attribute()* - inline $text_50 - inline $atomCommonAttributes_51 - remove () from expression list - simplify FLWOR expression: (attribute type { ("xhtml") }, element d... - rewrite fn:not(items) to fn:exists(items): not(empty($t_6)) -> exists($t_6) - pre-evaluate fn:false() to xs:boolean item: false() - inline local:atomPlainTextConstruct#2 - remove type check: $html_53 as xs:boolean? - inline $text_52 - inline $html_53 - simplify FLWOR expression: ((: text(), true :) let $txt_54 := types... Optimized Query: declare function local:escape($input_16) as xs:string? { serialize($input_16, map { "method": "xml" }) }; declare function local:content($content_2, $type_3 as xs:string?, $namespaces_4 as (map(xs:string, xs:string))?, $atomCommonAttributes_5 as attribute()*) as element(atom:content) { let $t_6 := if($type_3) then $type_3 else typeswitch($content_2) case element()* return "xml" case xs:string* return try { parse-xml($content_2) } catch * { if(matches(((: xs:string, true :) $content_2), "&lt;.*?&gt;", "ij")) then "html" else "text" } default return "text" return element Q{http://www.w3.org/2005/Atom}content { ((($namespaces_4 ! map:for-each(., function($suffix_39 as xs:string, $ns_38 as xs:string) as namespace-node() { namespace { $suffix_39 } { ($ns_38) } })), switch($t_6) case "html" return ((: text(), true :) let $txt_44 := typeswitch($content_2) case xs:string* return if(matches($content_2, "<.*?>", "ij")) then error() else if(matches($content_2, "&lt;.*?&gt;", "ij")) then error() else $content_2 case node() return if((count($content_2/node()/ancestor-or-self::node()) >= 3)) then error() else serialize($content_2, map { "method": "xml" }) default return "unmatched" return text { ($txt_44) }) case "text" return ((: text(), true :) let $txt_47 := typeswitch($content_2) case xs:string* return if(matches($content_2, "<.*?>", "ij")) then error() else if(matches($content_2, "&lt;.*?&gt;", "ij")) then error() else $content_2 case node() return if((count($content_2/node()/ancestor-or-self::node()) >= 3)) then error() else serialize($content_2, map { "method": "xml" }) default return "unmatched" return text { ($txt_47) }) case "xhtml" return (attribute type { ("xhtml") }, element div { ((namespace { "xhtml" } { ("http://www.w3.org/1999/xhtml") }, $content_2)) }) case "xml" return (attribute type { ("xhtml") }, element div { ((namespace { "xhtml" } { ("http://www.w3.org/1999/xhtml") }, $content_2)) }) case exists($t_6) return (attribute type { ($t_6) }, $content_2) default return ((: text(), true :) let $txt_54 := typeswitch($content_2) case xs:string* return if(matches($content_2, "<.*?>", "ij")) then error() else if(matches($content_2, "&lt;.*?&gt;", "ij")) then error() else $content_2 case node() return if((count($content_2/node()/ancestor-or-self::node()) >= 3)) then error() else serialize($content_2, map { "method": "xml" }) default return "unmatched" return text { ($txt_54) }))) } }; let $sh_25 := "

Color text and another color, and now back to the same.
O..." let $sp_26 := local:escape($sh_25) let $xh_27 := element p { (attribute style { ("color:#B22222") }, "Color text and ", element span { (attribute style { ("color:limegreen;") }, "another color") }, ", and now back to the same.", element br { () }, "Oh, and here's a ", element span { (attribute style { ("background-color:PaleGreen;") }, "different background color") }, " just in case you need it!") } return local:content($sh_25, (), (), ()) Query: declare namespace atom = "http://www.w3.org/2005/Atom"; declare namespace xhtml = "http://www.w3.org/1999/xhtml"; declare variable $local:unescaped-html-xml-test := "<.*?>"; declare variable $local:escaped-html-xml-test := "&lt;.*?&gt;"; declare function local:content( $content as item()*, $type as xs:string?, $namespaces as map(xs:string, xs:string)?, $atomCommonAttributes as attribute()*) as element(atom:content) { let $t := if (not($type)) then local:test-for-markup($content) else $type return element atom:content { $namespaces ! map:for-each(., function($suffix, $ns) { namespace { $suffix } { $ns } }) ,switch ($t) case "html" return local:atomPlainTextConstruct($content,true()) case "text" return local:atomPlainTextConstruct($content, false()) case "xhtml" return local:atomXHTMLTextConstruct($content, ()) case "xml" return local:atomXHTMLTextConstruct($content, ()) case (not(empty($t))) return ( attribute type { $t } ,$content ) default return local:atomPlainTextConstruct($content, false()) } }; declare function local:atomPlainTextConstruct( $text as item()*, $html as xs:boolean?) as text() { let $txt := typeswitch ($text) case xs:string* return if (matches($text, $local:unescaped-html-xml-test,"ij")) then if (count(html:parse($text)/*:html/*:body/node()/child::node() > 2)) then error() else serialize($text) else if (matches($text, $local:escaped-html-xml-test,"ij")) then if (count(parse-xml($text)/child::node() > 2)) then error() else $text else $text case node() return if (count($text/node()/ancestor-or-self::node()) > 2) then error() else local:escape($text) default return "unmatched" return text { $txt } }; declare function local:atomXHTMLTextConstruct( $text as item()*, $atomCommonAttributes as attribute()*) as item()* { $atomCommonAttributes ! . ,attribute type {"xhtml"} ,element div { namespace {"xhtml"} {"http://www.w3.org/1999/xhtml"} ,$text } }; declare function local:is-unescaped-markup( $string as xs:string) as xs:boolean { matches($string, $local:unescaped-html-xml-test, "ij") }; declare function local:is-escaped-markup( $string as xs:string) as xs:boolean { matches($string, $local:escaped-html-xml-test, "ij") }; declare function local:escape( $input as item()*) as xs:string? { serialize($input, map{"method":"xml"} ) }; declare function local:test-for-markup($input as item()*) { typeswitch ($input) case element()* return "xml" case xs:string* return try { parse-xml($input) } catch * { if ($input => local:is-escaped-markup()) then "html" else "text" } default return "text" }; let $sh := '

Color text and another color, and now back to the same.
Oh, and here's a different background color just in case you need it!

' let $sp := local:escape($sh) let $xh :=

Color text and another color, and now back to the same.
Oh, and here's a different background color just in case you need it!

return local:content($sh,(),(),())