Buggy code:
public class FileHostObject extends ScriptableObject { private static final Log log = LogFactory . getLog ( FileHostObject . class ) ; private static final String hostObjectName = "File" ; public static final String JAVASCRIPT_FILE_MANAGER = "hostobjects.file.filemanager" ; private static final String RESOURCE_MEDIA_TYPE_MAPPINGS_FILE = "mime.types" ; private static boolean mimeMapLoaded = false ; private JavaScriptFile file = null ; private JavaScriptFileManager manager = null ; private Context context = null ; private String path ; public static Scriptable jsConstructor ( Context cx , Object [ ] args , Function ctorObj , boolean inNewExpr ) throws ScriptException { } public String getClassName ( ) { } public static void jsFunction_open ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static void jsFunction_write ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static String jsFunction_read ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static String jsFunction_readAll ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static void jsFunction_close ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static boolean jsFunction_move ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static boolean jsFunction_saveAs ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static boolean jsFunction_del ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static long jsFunction_getLength ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static long jsFunction_getLastModified ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static String jsFunction_getName ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static boolean jsFunction_isExists ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static String jsFunction_getContentType ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } private static FileTypeMap loadMimeMap ( ) throws ScriptException { } public static Scriptable jsFunction_getStream ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public InputStream getInputStream ( ) throws ScriptException { } public OutputStream getOutputStream ( ) throws ScriptException { } public String getName ( ) throws ScriptException { } public JavaScriptFile getJavaScriptFile ( ) throws ScriptException { } public static boolean jsFunction_isDirectory ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static String jsFunction_getPath ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static boolean jsFunction_mkdir ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { } public static Object jsFunction_listFiles ( Context cx , Scriptable thisObj , Object [ ] args , Function funObj ) throws ScriptException { String functionName = "listFiles" ; int argsCount = args . length ; if ( argsCount != 0 ) { HostObjectUtil . invalidNumberOfArgs ( FileHostObject . hostObjectName , functionName , argsCount , false ) ; } FileHostObject fho = ( ( FileHostObject ) ( thisObj ) ) ; ArrayList < String > fpaths = fho . file . listFiles ( ) ; ArrayList < Scriptable > fhol = new ArrayList < Scriptable > ( ) ; for ( String jsf : fpaths ) { <START_BUG> fhol . add ( fho . context . newObject ( thisObj , "File" , new Object [ ] { "file:////" + jsf } ) ) ; <END_BUG> } return cx . newArray ( thisObj , fhol . toArray ( ) ) ; } No newline ; at end ; of file ; }

Fix:
fhol . add ( fho . context . newObject ( thisObj , "File" , new Object [ ] { jsf } ) ) ;