Replacing default FileSystemProvider

Michael Hall mik3hall at gmail.com
Sun Mar 28 14:44:41 UTC 2021



> On Mar 27, 2021, at 11:02 PM, Michael Hall <mik3hall at gmail.com> wrote:
> 
> 
> 
>> On Mar 25, 2021, at 9:25 PM, Michael Hall <mik3hall at gmail.com <mailto:mik3hall at gmail.com>> wrote:
>> 
>> Caused by: java.lang.ClassCastException: class us.hall.trz.osx.MacPath cannot be cast to class sun.nio.fs.UnixPath (us.hall.trz.osx.MacPath is in unnamed module of loader 'app'; sun.nio.fs.UnixPath is in module java.base of loader 'bootstrap')
>> 	at java.base/sun.nio.fs.UnixPath.compareTo(Unknown Source)
> 
> Maybe understand this a little bit.
> 
> My application REST API’s using Apache HttpClient are not working.
> 
> ava.lang.NoClassDefFoundError: Could not initialize class sun.security.ssl.SSLContextImpl$CustomizedTLSContext
> 	at java.base/java.lang.Class.forName0(Native Method)
> 	at java.base/java.lang.Class.forName(Unknown Source)
> 	at java.base/java.security.Provider$Service.getImplClass(Unknown Source)
> 	at java.base/java.security.Provider$Service.newInstance(Unknown Source)
> 
> Debugging messages show…
> 2021-03-27 22:34:16.849 HalfPipe[5244:239243] MacPath: unlimited
> 2021-03-27 22:34:16.849 HalfPipe[5244:239243] MacPath: /Users/mjh/HalfPipe/HalfPipe_jpkg/outputdir/HalfPipe.app/Contents/runtime/Contents/Home/conf/security/policy
> 2021-03-27 22:34:16.849 HalfPipe[5244:239243] MacPath: /Users/mjh/HalfPipe/HalfPipe_jpkg/outputdir/HalfPipe.app/Contents/runtime/Contents/Home/conf/security/policy
> 2021-03-27 22:34:16.850 HalfPipe[5244:239243] MacPath: /Users/mjh/HalfPipe/HalfPipe_jpkg/outputdir/HalfPipe.app/Contents/runtime/Contents/Home/conf/security/policy/unlimited
> 2021-03-27 22:34:16.850 HalfPipe[5244:239243] MacPath: /Users/mjh/HalfPipe/HalfPipe_jpkg/outputdir/HalfPipe.app/Contents/runtime/Contents/Home/conf/security/policy/unlimited
> 2021-03-27 22:34:16.854 HalfPipe[5244:239243] java.lang.Exception: UnixPath
> 
> …that I am trying to access security files in the runtime conf directory just before the error.
> This is very similar to this StackOverflow I found…
> 
> Apache HttpClient failing with Java 11 on macOS
> https://stackoverflow.com/questions/61185934/apache-httpclient-failing-with-java-11-on-macos <https://stackoverflow.com/questions/61185934/apache-httpclient-failing-with-java-11-on-macos>
> 
> Getting a nearly identical error when these files couldn’t be found.
> They are there for me but I think with my FileSystemProvider I instead get the ClassCastException from the Unix provider. I don’t get enough of the stack trace to know why I end up with a Unix provider. Maybe I could come up with a simple test case where I’d get the full error.
> 
> UnixPath for the source I have does…
> @Override
>     public int compareTo(Path other) {
>         int len1 = path.length;
>         int len2 = ((UnixPath) other).path.length;
> 
>         int n = Math.min(len1, len2);
>         byte v1[] = path;
>         byte v2[] = ((UnixPath) other).path;
> 
> Code that casts like this if it is reached will never work with an overridden DefaultFileSystemProvider instance. 
> 
> 
> 

Simple reproducing test case…

import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;

public class TestREST {

	
	public static void main(String[] args) {
		try (CloseableHttpClient client = HttpClientBuilder.create().build();) {
		}
		catch (ClassCastException cce) {
			System.out.println("as cce");
			cce.printStackTrace();
		}
		catch (java.io.IOException ioex) {
			System.out.println("as ioex");
		}
	}
}

Compile

javac -cp outputdir/HalfPipe.app/Contents/app/httpclient5-5.0.3.jar:outputdir/HalfPipe.app/Contents/app/httpcore5-5.0.2.jar TestREST.java

Run

java -cp .:outputdir/HalfPipe.app/Contents/app/httpclient5-5.0.3.jar:outputdir/HalfPipe.app/Contents/app/httpcore5-5.0.2.jar:outputdir/HalfPipe.app/Contents/app/slf4j-api-1.7.7.jar -Djava.nio.file.spi.DefaultFileSystemProvider=us.hall.trz.osx.MacFileSystemProvider TestREST

Which picks up my exploded provider in the current directory.
I haven’t figured out how to get the full ClassCastException stack trace or thought of any other way to determine why a Unix provider Path instance is involved. 
I could bug report if it seems to make sense? It does break functionality when I turn on my default provider for my application. 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20210328/64335ca0/attachment.htm>


More information about the nio-dev mailing list