Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in SpecificityUtils #139

Open
cimnine opened this issue Jul 27, 2020 · 0 comments
Open

NullPointerException in SpecificityUtils #139

cimnine opened this issue Jul 27, 2020 · 0 comments

Comments

@cimnine
Copy link

cimnine commented Jul 27, 2020

Caused by: java.lang.NullPointerException
	at io.milton.http.annotated.SpecificityUtils.sourceSpecifityIndex(SpecificityUtils.java:29) ~[milton-server-ce-2.7.2.4.jar:?]
	at io.milton.http.annotated.AbstractAnnotationHandler.getBestMethod(AbstractAnnotationHandler.java:100) ~[milton-server-ce-2.7.2.4.jar:?]
	at io.milton.http.annotated.AbstractAnnotationHandler.isCompatible(AbstractAnnotationHandler.java:183) ~[milton-server-ce-2.7.2.4.jar:?]
	at io.milton.http.annotated.AnnotationResourceFactory.instantiate(AnnotationResourceFactory.java:648) ~[milton-server-ce-2.7.2.4.jar:?]
	at io.milton.http.annotated.AnnotationResourceFactory.createAndAppend(AnnotationResourceFactory.java:792) ~[milton-server-ce-2.7.2.4.jar:?]
	at io.milton.http.annotated.ChildrenOfAnnotationHandler.execute(ChildrenOfAnnotationHandler.java:68) ~[milton-server-ce-2.7.2.4.jar:?]
	at io.milton.http.annotated.AnnoCollectionResource.initChildren(AnnoCollectionResource.java:176) ~[milton-server-ce-2.7.2.4.jar:?]
	... 42 more

An NPE is occurring in https://github.com/miltonio/milton2/blob/master/milton-server-ce/src/main/java/io/milton/http/annotated/SpecificityUtils.java#L28.

The following happens:

# Params
methodType = "interface java.nio.file.Path"
actualType = "class com.google.common.jimfs.JimfsPath"

# Code Flow
c = actualType // c = "class com.google.common.jimfs.JimfsPath"
i = 0
while (!methodType.equals(c)) // true
c = c.getSuperclass();  // c = "class java.lang.Object"
while (!methodType.equals(c)) // true
c = c.getSuperclass(); // c = null
while(!methodType.equals(c)) // true
c = c.getSuperclass(); // ==> NullPointerException, because c is null

My controller looks like this:

package foo.bar;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import io.milton.annotations.ChildrenOf;
import io.milton.annotations.ResourceController;
import io.milton.annotations.Root;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;

@ResourceController
public class MinimalVirtualFSDavController {
	private final FileSystem fs = Jimfs.newFileSystem(Configuration.unix());

	public MinimalVirtualFSDavController() {
		try {
			Path dir = Files.createDirectory(fs.getPath("/foo"));
			Files.writeString(fs.getPath(dir.toString(), "bar1"), "Hello", StandardCharsets.UTF_8);
			Files.writeString(fs.getPath(dir.toString(), "bar2"), "Hello", StandardCharsets.UTF_8);
			Files.writeString(fs.getPath(dir.toString(), "bar3"), "Hello", StandardCharsets.UTF_8);
			Files.writeString(fs.getPath(dir.toString(), "bar4"), "Hello", StandardCharsets.UTF_8);
			Files.writeString(fs.getPath(dir.toString(), "bar5"), "Hello", StandardCharsets.UTF_8);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Root
	public Path root() {
		return fs.getPath("/");
	}

	@ChildrenOf
	public List<Path> getChildrenOfDavFolder(Path p) {
		try {
			List<Path> collect = Files.list(p).collect(Collectors.toList());
			return collect;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return List.of();
	}
}

How could I implement this in a way that works with milton? Does milton even already support the java.nio.file.FileSystem API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant