apache / apache/lucene

FilterPath.resolve(Path) doesn't work [LUCENE-10227]

Open
#11,263 10 comments 0 reactions 0 assignees View on GitHub
legacy-jira-priority:Major type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

Short reproducing sample that captures the error I encounter when trying to write a unit test:

```java
package org.apache.lucene.mockfile;

import org.apache.lucene.util.LuceneTestCase;
import org.junit.Test;

import java.nio.file.Path;

public class TestFilterPath extends LuceneTestCase {

`@Test`
public void testMultiwrap() throws Exception {
Path source = LuceneTestCase.createTempDir();
Path child = source.resolve("child");
assertEquals(source, child.getParent());

child = source.resolve(Path.of("child")); // This line throws exception
assertEquals(source, child.getParent());
}
}
```

When running this test (on my Mac) I get the following:

```
mismatch, expected: FilterPath, got: class sun.nio.fs.UnixPath
java.nio.file.ProviderMismatchException: mismatch, expected: FilterPath, got: class sun.nio.fs.UnixPath
at __randomizedtesting.SeedInfo.seed([318296D60FE95435:125A6A9E9053DCC3]:0)
at org.apache.lucene.mockfile.FilterPath.toDelegate(FilterPath.java:292)
at org.apache.lucene.mockfile.FilterPath.resolve(FilterPath.java:151)
at org.apache.lucene.mockfile.TestFilterPath.testMultiwrap(TestFilterPath.java:16)
```

Part of the problem here might be that `createTempDir()` gives me a `FilterPath` wrapped four layers deep.
Part of the problem might be that resolve calls toDelegate which is too strict about what it would accept?

I'm not sure what the intent of all of these wrappings is, so I'm not completely sure how to fix it.

---
Migrated from [LUCENE-10227](https://issues.apache.org/jira/browse/LUCENE-10227) by Mike Drob (@madrob), updated Nov 13 2021

Contributor guide

Open the contributing guide

Research direction

Start with FilterPath.resolve(Path) and toDelegate in FilterPath.java, using the stack trace locations, then reproduce the failure with the TestFilterPath.testMultiwrap sample. Compare the String and Path resolve cases and inspect the wrapping behavior described in the issue. Done means the Path overload no longer raises ProviderMismatchException and both parent assertions pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.