-
Bug
-
Resolution: Duplicate
-
P2
-
6
-
generic
-
generic
javax.tool.JavaFileManager.getFileForInput(): spec for packageName parameter isn't actual
The spec states:
packageName - a package name as defined in the Java Language Specification
It seems to be wrong.
Note: I think packageName parameter for getFileForInput method is superfluous because any file (especially non-JavaFileObject) can be fully specified via relativeName. Now the same file can be specified using different sets of parameters.
What about non-letter characters in file path?
test:
----------------------
import javax.tools.*;
import java.io.File;
import java.net.URI;
import java.util.Collections;
public class test4 {
static public void main(String[] args){
URI uri = new File(".").toURI().normalize();
File dir = new File( uri );
StandardJavaFileManager sfm =
ToolProvider.getSystemJavaCompilerTool().
getStandardFileManager( new DiagnosticCollector<JavaFileObject>() );
JavaFileManager.Location location = StandardJavaFileManager.StandardLocation.SOURCE_PATH;
sfm.setLocation( location, Collections.singleton(dir) );
try {
String packageName = "tra-la-la/..";
FileObject fo = sfm.getFileForInput( location, packageName, URI.create("test4.java") );
if( fo != null )
System.out.println( "package name = " + packageName );
} catch( java.io.IOException x ){
x.printStackTrace(System.out);
}
}
}
----------------------
result:
----------------------
package name = tra-la-la/..
Is it possible to specify results of this method more precisely in exceptions part?
For example, to remove 'may be thrown'.
The spec states:
packageName - a package name as defined in the Java Language Specification
It seems to be wrong.
Note: I think packageName parameter for getFileForInput method is superfluous because any file (especially non-JavaFileObject) can be fully specified via relativeName. Now the same file can be specified using different sets of parameters.
What about non-letter characters in file path?
test:
----------------------
import javax.tools.*;
import java.io.File;
import java.net.URI;
import java.util.Collections;
public class test4 {
static public void main(String[] args){
URI uri = new File(".").toURI().normalize();
File dir = new File( uri );
StandardJavaFileManager sfm =
ToolProvider.getSystemJavaCompilerTool().
getStandardFileManager( new DiagnosticCollector<JavaFileObject>() );
JavaFileManager.Location location = StandardJavaFileManager.StandardLocation.SOURCE_PATH;
sfm.setLocation( location, Collections.singleton(dir) );
try {
String packageName = "tra-la-la/..";
FileObject fo = sfm.getFileForInput( location, packageName, URI.create("test4.java") );
if( fo != null )
System.out.println( "package name = " + packageName );
} catch( java.io.IOException x ){
x.printStackTrace(System.out);
}
}
}
----------------------
result:
----------------------
package name = tra-la-la/..
Is it possible to specify results of this method more precisely in exceptions part?
For example, to remove 'may be thrown'.
- duplicates
-
JDK-6409829 JSR 199: enforce the use of valid package and class names in get{Java,}FileFor{Input,Output}
-
- Closed
-