Skip to content

Commit 52ba814

Browse files
committed
open-api: javadoc parser NPE
- fix #3840
1 parent 8bda0f1 commit 52ba814

File tree

5 files changed

+75
-24
lines changed

5 files changed

+75
-24
lines changed

modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/javadoc/JavaDocNode.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ public int getColumnNumber() {
156156
return 0;
157157
}
158158

159-
// @Override
160-
// public DetailNode[] getChildren() {
161-
// return new DetailNode[0];
162-
// }
163-
164159
@Override
165160
public DetailNode getParent() {
166161
return null;

modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/javadoc/JavaDocStream.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private static <T> Iterator<T> backwardIterator(ASTNode<T> node) {
145145

146146
@Override
147147
public boolean hasNext() {
148-
return it.getParent() != null;
148+
return it.getNode() != null && it.getParent() != null;
149149
}
150150

151151
@Override
@@ -163,14 +163,15 @@ private static <T> Iterator<T> forwardIterator(ASTNode<T> node, boolean full) {
163163

164164
@Override
165165
public boolean hasNext() {
166-
return it != null;
166+
return it != null && it.getNode() != null;
167167
}
168168

169169
@Override
170170
public T next() {
171-
if (it.getNextSibling() != null) {
171+
var sibling = it.getNextSibling();
172+
if (sibling != null) {
172173
if (full || it != node) {
173-
stack.push(it.getNextSibling());
174+
stack.push(sibling);
174175
}
175176
}
176177
var current = it;
@@ -210,22 +211,26 @@ static ASTNode<DetailNode> javadoc(DetailNode node) {
210211
static <N> ASTNode<N> ast(
211212
N node, Function<N, N> parent, Function<N, N> child, Function<N, N> sibling) {
212213
return new ASTNode<>() {
213-
@Override
214-
public ASTNode<N> getParent() {
215-
var parentNode = parent.apply(node);
216-
if (parentNode == null) {
214+
215+
private ASTNode<N> apply(Function<N, N> fn) {
216+
if (node == null) {
217217
return null;
218218
}
219-
return ast(parentNode, parent, child, sibling);
219+
var result = fn.apply(node);
220+
if (result == null) {
221+
return null;
222+
}
223+
return ast(result, parent, child, sibling);
224+
}
225+
226+
@Override
227+
public ASTNode<N> getParent() {
228+
return apply(parent);
220229
}
221230

222231
@Override
223232
public ASTNode<N> getFirstChild() {
224-
var childNode = child.apply(node);
225-
if (childNode == null) {
226-
return null;
227-
}
228-
return ast(childNode, parent, child, sibling);
233+
return apply(child);
229234
}
230235

231236
@Override
@@ -235,11 +240,7 @@ public N getNode() {
235240

236241
@Override
237242
public ASTNode<N> getNextSibling() {
238-
var siblingNode = sibling.apply(node);
239-
if (siblingNode == null) {
240-
return null;
241-
}
242-
return ast(siblingNode, parent, child, sibling);
243+
return apply(sibling);
243244
}
244245
};
245246
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package issues.i3840;
7+
8+
import static io.jooby.openapi.MvcExtensionGenerator.toMvcExtension;
9+
10+
import io.jooby.Jooby;
11+
12+
public class App3840 extends Jooby {
13+
{
14+
mvc(toMvcExtension(C3840.class));
15+
}
16+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package issues.i3840;
7+
8+
import java.util.concurrent.CompletableFuture;
9+
10+
import io.jooby.annotation.GET;
11+
import io.jooby.annotation.Path;
12+
13+
@Path("/3840")
14+
public class C3840 {
15+
16+
@GET
17+
public CompletableFuture<String> hello() {
18+
return CompletableFuture.supplyAsync(() -> "hello")
19+
.whenComplete((e, o) -> o.printStackTrace()); // <- root cause line
20+
}
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package issues.i3840;
7+
8+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
9+
10+
import io.jooby.openapi.OpenAPIResult;
11+
import io.jooby.openapi.OpenAPITest;
12+
13+
public class Issue3840 {
14+
@OpenAPITest(value = App3840.class)
15+
public void shouldNotThrowNPE(OpenAPIResult result) {
16+
assertThat(result).isNotNull();
17+
}
18+
}

0 commit comments

Comments
 (0)