Skip to content

Commit

Permalink
Fix nullability issues on Xml.DocTypeDecl (#3354)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Leitschuh <Jonathan.Leitschuh@gmail.com>
  • Loading branch information
JLLeitschuh authored Jun 27, 2023
1 parent 068af07 commit 7db5041
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public Xml.DocTypeDecl visitDoctypedecl(XMLParser.DoctypedeclContext ctx) {
Markers.EMPTY,
name,
externalId,
internalSubset,
internalSubset == null ? Collections.emptyList() : internalSubset,
externalSubsets,
beforeTagDelimiterPrefix);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ public String getPrefix() {

Markers markers;
Ident name;
@Nullable
Ident externalId;
List<Ident> internalSubset;

Expand Down
21 changes: 21 additions & 0 deletions rewrite-xml/src/test/java/org/openrewrite/xml/XmlParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,35 @@
package org.openrewrite.xml;

import org.junit.jupiter.api.Test;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Issue;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.xml.tree.Xml;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.openrewrite.test.RewriteTest.toRecipe;
import static org.openrewrite.xml.Assertions.xml;

@SuppressWarnings({"CheckDtdRefs", "CheckTagEmptyBody"})
class XmlParserTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec.recipe(toRecipe(
() -> new XmlVisitor<>() {
@Override
public Xml visitDocTypeDecl(Xml.DocTypeDecl docTypeDecl, ExecutionContext executionContext) {
assertNotNull(docTypeDecl.getPrefixUnsafe(), "prefix should not be null");
assertNotNull(docTypeDecl.getName(), "name should not be null");
assertNotNull(docTypeDecl.getInternalSubset(), "internalSubset should not be null");
assertNotNull(docTypeDecl.getBeforeTagDelimiterPrefix(), "beforeTagDelimiterPrefix should not be null");
return super.visitDocTypeDecl(docTypeDecl, executionContext);
}
}
));
}

@Issue("https://github.com/openrewrite/rewrite/issues/2189")
@Test
void specialCharacters() {
Expand Down

0 comments on commit 7db5041

Please sign in to comment.