asciidoctor / asciidoctorj

:coffee: Java bindings for Asciidoctor. Asciidoctor on the JVM!
http://asciidoctor.org
Apache License 2.0
623 stars 173 forks source link

Support `null` as an empty source #1146

Closed abelsromero closed 1 year ago

abelsromero commented 1 year ago

convert and load fail with a java assert exception when input is null String. For satefy we should consider null as an empty value that returns an empty document, for both convert and load.

In the case of convert with Reader I'd keep the current exception, at most, add Objects.requireNonNull(reader, "reader"); to https://github.com/asciidoctor/asciidoctorj/blob/b1902506e70db29bdd2fd5496f1f531e5fbccd13/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/IOUtils.java#L22 so the users gets a hint of where the issue is without adding too much complexity.

java.lang.NullPointerException: reader
    at java.base/java.util.Objects.requireNonNull(Objects.java:233)
    at org.asciidoctor.jruby.internal.IOUtils.readFull(IOUtils.java:24)
    at org.asciidoctor.jruby.internal.JRubyAsciidoctor.convert(JRubyAsciidoctor.java:351)
    at org.asciidoctor.jruby.internal.JRubyAsciidoctor.convert(JRubyAsciidoctor.java:358)
    at org.asciidoctor.jruby.ast.impl.SectionImplTest.temporal(SectionImplTest.java:28)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at