Skip to content

Commit

Permalink
java.net.URI.toURI broken (#460)
Browse files Browse the repository at this point in the history
* created unit test for 'toURI' in 'File' model class

* removed 'non-null' check from 'toURI' in FileTest.java

* changed way of URI generation in FileTest class

* created 'JavaNetUriAccess' interface and added getter setter for the same in SharedSceret class
  • Loading branch information
Harsh4902 authored Jun 7, 2024
1 parent 579284f commit 0916082
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package jdk.internal.misc;

public interface JavaNetUriAccess {
// We can add more necessary methods here
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class SharedSecrets {
private static JavaObjectInputStreamAccess javaObjectInputStreamAccess;
private static JavaObjectInputFilterAccess javaObjectInputFilterAccess;
private static JavaObjectInputStreamReadString javaObjectInputStreamReadString;
private static JavaNetUriAccess javaNetUriAccess;

// (required for EnumSet ops)
public static JavaLangAccess getJavaLangAccess() {
Expand Down Expand Up @@ -207,4 +208,12 @@ public static JavaObjectInputStreamReadString getJavaObjectInputStreamReadString
public static void setJavaObjectInputStreamReadString(JavaObjectInputStreamReadString access) {
javaObjectInputStreamReadString = access;
}

public static void setJavaNetUriAccess(JavaNetUriAccess jnua) {
javaNetUriAccess = jnua;
}

public static JavaNetUriAccess getJavaNetUriAccess() {
return javaNetUriAccess;
}
}
20 changes: 19 additions & 1 deletion src/tests/gov/nasa/jpf/test/java/io/FileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.junit.After;
import org.junit.AfterClass;
Expand Down Expand Up @@ -102,5 +104,21 @@ public void testEquals() {
assert file.equals(new Object()) == false;
}
}


@Test
public void testToURI(){
if(verifyNoPropertyViolation()){
File file = new File("testfile.txt");
URI expectedURI = null;
try {
expectedURI = new URI("file:" + file.getAbsolutePath());
} catch (URISyntaxException e) {
fail("URISyntaxException thrown while constructing expected URI");
}

URI actualURI = file.toURI();
System.out.println(actualURI);
assertEquals("The URIs should be equal",expectedURI,actualURI);
}
}
}

0 comments on commit 0916082

Please sign in to comment.