JDK-6415881 : JSR 199: DefaultFileManager.getFileForInput does not validate input
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2006-04-20
  • Updated: 2011-01-19
  • Resolved: 2006-04-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6Resolved
Related Reports
Duplicate :  
Description
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'.

Comments
EVALUATION There seems to be a similar problem with the class name in getJavaFileForInput.
21-04-2006

EVALUATION There are a few issues reported in this one bug. Executive summary: I only accept the problem about invalid package names being accepted. The package name might seem superfluous but using file names with file separator characters is brittle and should be avoided. Finally, regarding exceptions: this method is supposed to be implemented by users of javax.tools. The current specification is written to make it easy for users to implement this interface, not to make it easy to use it.
21-04-2006