[TIMOB-4546] Ti.Filesystem.getFile() exception when dot-dot filesystem path notation used
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2017-06-16T22:25:29.000+0000 |
Affected Version/s | Release 1.7.1 |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Paul Dowsett |
Assignee | Ingo Muschenetz |
Created | 2011-07-04T16:44:18.000+0000 |
Updated | 2017-06-16T22:25:29.000+0000 |
Description
Note the somewhat related TIMOB-4543
When a path that uses "dot-dot" filesystem path notation (ie
../
, to signify "move to parent directory") is passed to Ti.Filesystem.getFile
, an exception is generated on 1.7.1, but executes as expected on 1.6.3. One of the difficulties this causes is that database files cannot be accessed via the Ti.Filesystem.applicationDataDirectory
path, making it necessary for users to use [messy workarounds](http://developer.appcelerator.com/question/96771/location-of-titanium-sql-database-on-android#answer-172981), ie: 'file:///data/data/' + Ti.App.getID() + '/databases/'
The following code demonstrates the issue:
var fileName = 'test7.txt';
Ti.API.info("fileName: " + fileName);
var filePath = Ti.Filesystem.applicationDataDirectory + '../databases';
Ti.API.info("filePath: " + filePath);
var thisFile = Ti.Filesystem.getFile(filePath, fileName);
Ti.API.info("thisFile.nativePath: " + thisFile.nativePath);
When run on 1.6.3, no exception is generated:
*Titanium 1.6.3 (2011/05/06 13:58 7b34a7...)*
10289 KrollContext D (kroll$1: app://app.js) [337,735] Running evaluated script: file:///android_asset/Resources/app.js
10289 dalvikvm D GC_FOR_MALLOC freed 4836 objects / 323320 bytes in 56ms
10289 TiAPI I (kroll$1: app://app.js) [375,1110] fileName: test7.txt
10289 TiAPI I (kroll$1: app://app.js) [2,1112] filePath: appdata-private://../databases
10289 TiAPI I (kroll$1: app://app.js) [21,1133] thisFile.nativePath: file:///data/data/com.testing.testing7/app_appdata/../databases/test7.txt
10289 TiRootActivity I (main) [0,0] checkpoint, on root activity resume. context = org.appcelerator.titanium.TiContext@44ec6910
When run on 1.7.1, an exception is generated:
*Titanium 1.7.1 (2011/06/17 00:13 293a6d...)*
9285 KrollContext D (kroll$1: app://app.js) [2,1172] Running evaluated script: file:///android_asset/Resources/app.js
9285 TiAPI I (kroll$1: app://app.js) [101,1273] fileName: test7.txt
9285 TiAPI I (kroll$1: app://app.js) [2,1275] filePath: appdata-private://../databases
9285 KrollMethod E (kroll$1: app://app.js) [15,1290] Exception calling kroll method getFile, invocation: null ]
9285 KrollMethod E java.lang.NullPointerException
9285 KrollMethod E at java.net.URI$Helper.isValidDomainName(URI.java:631)
9285 KrollMethod E at java.net.URI$Helper.isValidHost(URI.java:595)
9285 KrollMethod E at java.net.URI$Helper.parseAuthority(URI.java:544)
9285 KrollMethod E at java.net.URI$Helper.parseURI(URI.java:404)
9285 KrollMethod E at java.net.URI$Helper.access$100(URI.java:302)
9285 KrollMethod E at java.net.URI.<init>(URI.java:87)
9285 KrollMethod E at org.appcelerator.titanium.util.TiUrl.absoluteUrl(TiUrl.java:251)
9285 KrollMethod E at org.appcelerator.titanium.util.TiUrl.resolve(TiUrl.java:195)
9285 KrollMethod E at org.appcelerator.titanium.TiContext.resolveUrl(TiContext.java:151)
9285 KrollMethod E at ti.modules.titanium.filesystem.FileProxy.<init>(FileProxy.java:80)
9285 KrollMethod E at ti.modules.titanium.filesystem.FileProxy.<init>(FileProxy.java:49)
9285 KrollMethod E at ti.modules.titanium.filesystem.FilesystemModule.getFile(FilesystemModule.java:69)
9285 KrollMethod E at ti.modules.titanium.filesystem.FilesystemModuleBindingGen$8.invoke(FilesystemModuleBindingGen.java:346)
9285 KrollMethod E at org.appcelerator.kroll.KrollMethod.call(KrollMethod.java:51)
9285 KrollMethod E at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1701)
9285 KrollMethod E at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
9285 KrollMethod E at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
9285 KrollMethod E at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
9285 KrollMethod E at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3177)
9285 KrollMethod E at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
9285 KrollMethod E at org.mozilla.javascript.Context.evaluateReader(Context.java:1142)
9285 KrollMethod E at org.appcelerator.titanium.kroll.KrollContext$DefaultEvaluator.evaluateFile(KrollContext.java:105)
9285 KrollMethod E at org.appcelerator.titanium.kroll.KrollContext.evaluateScript(KrollContext.java:306)
9285 KrollMethod E at org.appcelerator.titanium.kroll.KrollContext.handleEvalFile(KrollContext.java:318)
9285 KrollMethod E at org.appcelerator.titanium.kroll.KrollContext.handleMessage(KrollContext.java:217)
9285 KrollMethod E at org.appcelerator.titanium.TiMessageQueue.handleMessage(TiMessageQueue.java:223)
9285 KrollMethod E at android.os.Handler.dispatchMessage(Handler.java:95)
9285 KrollMethod E at android.os.Looper.loop(Looper.java:123)
9285 KrollMethod E at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:86)
9285 KrollContext E (kroll$1: app://app.js) [25,1315] Error evaluating source: Wrapped java.lang.NullPointerException (file:///android_asset/Resources/app.js#1042)
9285 KrollContext E org.mozilla.javascript.WrappedException: Wrapped java.lang.NullPointerException (file:///android_asset/Resources/app.js#1042)
9285 KrollContext E at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1786)
9285 KrollContext E at org.appcelerator.kroll.KrollMethod.call(KrollMethod.java:85)
9285 KrollContext E at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1701)
9285 KrollContext E at script(file:///android_asset/Resources/app.js:1042)
9285 KrollContext E at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
9285 KrollContext E at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
9285 KrollContext E at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
9285 KrollContext E at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3177)
9285 KrollContext E at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
9285 KrollContext E at org.mozilla.javascript.Context.evaluateReader(Context.java:1142)
9285 KrollContext E at org.appcelerator.titanium.kroll.KrollContext$DefaultEvaluator.evaluateFile(KrollContext.java:105)
9285 KrollContext E at org.appcelerator.titanium.kroll.KrollContext.evaluateScript(KrollContext.java:306)
9285 KrollContext E at org.appcelerator.titanium.kroll.KrollContext.handleEvalFile(KrollContext.java:318)
9285 KrollContext E at org.appcelerator.titanium.kroll.KrollContext.handleMessage(KrollContext.java:217)
9285 KrollContext E at org.appcelerator.titanium.TiMessageQueue.handleMessage(TiMessageQueue.java:223)
9285 KrollContext E at android.os.Handler.dispatchMessage(Handler.java:95)
9285 KrollContext E at android.os.Looper.loop(Looper.java:123)
9285 KrollContext E at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:86)
9285 KrollContext E Caused by: java.lang.NullPointerException
9285 KrollContext E at java.net.URI$Helper.isValidDomainName(URI.java:631)
9285 KrollContext E at java.net.URI$Helper.isValidHost(URI.java:595)
9285 KrollContext E at java.net.URI$Helper.parseAuthority(URI.java:544)
9285 KrollContext E at java.net.URI$Helper.parseURI(URI.java:404)
9285 KrollContext E at java.net.URI$Helper.access$100(URI.java:302)
9285 KrollContext E at java.net.URI.<init>(URI.java:87)
9285 KrollContext E at org.appcelerator.titanium.util.TiUrl.absoluteUrl(TiUrl.java:251)
9285 KrollContext E at org.appcelerator.titanium.util.TiUrl.resolve(TiUrl.java:195)
9285 KrollContext E at org.appcelerator.titanium.TiContext.resolveUrl(TiContext.java:151)
9285 KrollContext E at ti.modules.titanium.filesystem.FileProxy.<init>(FileProxy.java:80)
9285 KrollContext E at ti.modules.titanium.filesystem.FileProxy.<init>(FileProxy.java:49)
9285 KrollContext E at ti.modules.titanium.filesystem.FilesystemModule.getFile(FilesystemModule.java:69)
9285 KrollContext E at ti.modules.titanium.filesystem.FilesystemModuleBindingGen$8.invoke(FilesystemModuleBindingGen.java:346)
9285 KrollContext E at org.appcelerator.kroll.KrollMethod.call(KrollMethod.java:51)
9285 KrollContext E ... 15 more
9285 TiJSError E (kroll$1: app://app.js) [19,1334] ----- Titanium Javascript Runtime Error -----
9285 TiJSError E (kroll$1: app://app.js) [10,1344] - In file:///android_asset/Resources/app.js:1042,0
9285 TiJSError E (kroll$1: app://app.js) [2,1346] - Message: Wrapped java.lang.NullPointerException (file:///android_asset/Resources/app.js#1042)
9285 TiJSError E (kroll$1: app://app.js) [5,1351] - Source: null
9285 TiRootActivity I (main) [0,0] checkpoint, on root activity resume. context = org.appcelerator.titanium.TiContext@44ecf690
After a discussion with Don, it transpires that this behavior is by design, as it should not be possible to advance above the applicationDataDirectory. The ability to do this in versions below 1.7.X was allowed due to a bug. To access other directories, the workaround at the moment is to use
'file:///data/data/' + Ti.App.getID()
Closing ticket due to time passed and lack of progress in the past few years. Any further problems, please file a new ticket.