JDK-8149604 : javac could wrap user provided file managers
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: New
  • Resolution: Unresolved
  • Submitted: 2016-02-10
  • Updated: 2016-02-20
Related Reports
Relates :  
Relates :  
Description
Currently, javac allows a user to specify a file manager to the JavaCompiler API.

The current behavior is that specifying some options, like -classpath, -source, etc, have an unspecified permanent side effect on the user provided file manager.

In addition, as noted in JDK-8139607, options like -release only work in conjunction with a StandardJavaFileManager.

A different approach would be for javac to "wrap" any user provided file manager with an instance-specific file manager, such that any changes resulting from javac options are confined to that instance, and not propagated to the user-provided file manager.

Thus, the behavior of methods in such a wrapper would be: 
    if this method is affected by local changes, impl the method locally; otherwise, delegate to the user provided file manager.

Note that (separately) the user file manager is already wrapped using ClientCodeWrapper, which exists to trap exceptions in a user provided file manager.   The wrapping described here would be in addition to the use of ClientCodeWrapper.

Comments
Handling MR-jars may be a bit more interesting.
11-02-2016

Setting the various paths is easy to intercept. Slightly more subtle will be to handle -encoding. If the user does not specify -encoding to javac, the wrapper file manager should delegate the character-oriented methods methods in the user provided file manager. If the user does specify -encoding, the wrapper file manager should implement the character-oriented methods, by delegating to the byte-oriented methods in the user provided file manager, and applying the specified encoding.
11-02-2016