Problem
1.7.2 introduced a regression: file.read() crashes with an exception.
Reproduction
The Kitchensink's filesystem.js demonstrates this: exception is generated when file.read() is called.
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'text.txt');
Ti.API.info('file = ' + f);
var contents = f.read();
Ti.API.info("contents blob object = "+contents);
Ti.API.info('contents = ' + contents.text);
Ti.API.info('mime type = ' + contents.mimeType);
Ti.API.info('nativePath = ' + f.nativePath);
Ti.API.info('exists = ' + f.exists());
Ti.API.info('size = ' + f.size);
Ti.API.info('readonly = ' + f.readonly);
Ti.API.info('symbolicLink = ' + f.symbolicLink);
Ti.API.info('executable = ' + f.executable);
Ti.API.info('hidden = ' + f.hidden);
Ti.API.info('writeable = ' + f.writeable);
Ti.API.info('name = ' + f.name);
Ti.API.info('extension = ' + f.extension());
Ti.API.info('resolve = ' + f.resolve());
Ti.API.info('created = ' + String(new Date(f.createTimestamp()))); // #2085 test
The Exception That Is Thrown
D/KrollContext( 427): (kroll$5: app://examples/filesystem.js) [4031,18273] Running evaluated script: app://examples/filesystem.js
I/TiAPI ( 427): (kroll$5: app://examples/filesystem.js) [327,18600] Resources Directory :app://
I/TiAPI ( 427): (kroll$5: app://examples/filesystem.js) [17,18617] Temp Directory :undefined
I/TiAPI ( 427): (kroll$5: app://examples/filesystem.js) [4,18621] Application Directory :null
I/TiAPI ( 427): (kroll$5: app://examples/filesystem.js) [4,18625] Application Data Directory :appdata-private://
I/TiAPI ( 427): (kroll$5: app://examples/filesystem.js) [11,18636] Application Support Directory :undefined
I/TiAPI ( 427): (kroll$5: app://examples/filesystem.js) [16,18652] External Storage Available :true
I/TiAPI ( 427): (kroll$5: app://examples/filesystem.js) [12,18664] Separator :/
I/TiAPI ( 427): (kroll$5: app://examples/filesystem.js) [5,18669] Line Ending :
I/TiAPI ( 427): (kroll$5: app://examples/filesystem.js) [28,18697] file = [object TiFileProxy]
D/dalvikvm( 427): GC_CONCURRENT freed 606K, 37% free 5366K/8391K, external 1644K/1676K, paused 9ms+7ms
D/TiFastDev( 427): (kroll$5: app://examples/filesystem.js) [227,18924] sent tokens successfully
E/KrollContext( 427): (kroll$5: app://examples/filesystem.js) [8,18932] Error: size < 0
E/KrollContext( 427): java.lang.IllegalArgumentException: size < 0
E/KrollContext( 427): at java.io.ByteArrayOutputStream.<init>(ByteArrayOutputStream.java:65)
E/KrollContext( 427): at org.appcelerator.titanium.util.TiStreamHelper.toByteArray(TiStreamHelper.java:106)
E/KrollContext( 427): at org.appcelerator.titanium.TiBlob.getBytes(TiBlob.java:120)
E/KrollContext( 427): at org.appcelerator.titanium.TiBlob.getText(TiBlob.java:216)
E/KrollContext( 427): at org.appcelerator.titanium.TiBlob.toString(TiBlob.java:259)
E/KrollContext( 427): at org.appcelerator.kroll.KrollProxy.getDefaultValue(KrollProxy.java:708)
E/KrollContext( 427): at org.appcelerator.kroll.KrollObject.getDefaultValue(KrollObject.java:155)
E/KrollContext( 427): at org.mozilla.javascript.ScriptRuntime.add(ScriptRuntime.java:2668)
E/KrollContext( 427): at org.mozilla.javascript.Interpreter.do_add(Interpreter.java:3039)
E/KrollContext( 427): at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1325)
E/KrollContext( 427): at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
E/KrollContext( 427): at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
E/KrollContext( 427): at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
E/KrollContext( 427): at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3177)
E/KrollContext( 427): at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
E/KrollContext( 427): at org.mozilla.javascript.Context.evaluateReader(Context.java:1142)
E/KrollContext( 427): at org.appcelerator.titanium.kroll.KrollContext$DefaultEvaluator.evaluateFile(KrollContext.java:105)
E/KrollContext( 427): at org.appcelerator.titanium.kroll.KrollContext.evaluateScript(KrollContext.java:306)
E/KrollContext( 427): at org.appcelerator.titanium.kroll.KrollContext.handleEvalFile(KrollContext.java:318)
E/KrollContext( 427): at org.appcelerator.titanium.kroll.KrollContext.handleMessage(KrollContext.java:217)
E/KrollContext( 427): at org.appcelerator.titanium.TiMessageQueue.handleMessage(TiMessageQueue.java:223)
E/KrollContext( 427): at android.os.Handler.dispatchMessage(Handler.java:95)
E/KrollContext( 427): at android.os.Looper.loop(Looper.java:130)
E/KrollContext( 427): at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:86)
W/dalvikvm( 427): threadid=13: thread exiting with uncaught exception (group=0x40015560)
E/TiUncaughtHandler( 427): (kroll$5: app://examples/filesystem.js) [60,18992] Sending event: exception on thread: kroll$5: app://examples/filesystem.js msg:org.mozilla.javascript.WrappedException: Wrapped java.lang.IllegalArgumentException: size < 0; Titanium 1.7.2,2011/07/21 09:36,97c3689
E/TiUncaughtHandler( 427): org.mozilla.javascript.WrappedException: Wrapped java.lang.IllegalArgumentException: size < 0
E/TiUncaughtHandler( 427): at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1786)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.kroll.KrollContext$DefaultEvaluator.handleException(KrollContext.java:148)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.kroll.KrollContext.handleEvalFile(KrollContext.java:325)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.kroll.KrollContext.handleMessage(KrollContext.java:217)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.TiMessageQueue.handleMessage(TiMessageQueue.java:223)
E/TiUncaughtHandler( 427): at android.os.Handler.dispatchMessage(Handler.java:95)
E/TiUncaughtHandler( 427): at android.os.Looper.loop(Looper.java:130)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:86)
E/TiUncaughtHandler( 427): Caused by: java.lang.IllegalArgumentException: size < 0
E/TiUncaughtHandler( 427): at java.io.ByteArrayOutputStream.<init>(ByteArrayOutputStream.java:65)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.util.TiStreamHelper.toByteArray(TiStreamHelper.java:106)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.TiBlob.getBytes(TiBlob.java:120)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.TiBlob.getText(TiBlob.java:216)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.TiBlob.toString(TiBlob.java:259)
E/TiUncaughtHandler( 427): at org.appcelerator.kroll.KrollProxy.getDefaultValue(KrollProxy.java:708)
E/TiUncaughtHandler( 427): at org.appcelerator.kroll.KrollObject.getDefaultValue(KrollObject.java:155)
E/TiUncaughtHandler( 427): at org.mozilla.javascript.ScriptRuntime.add(ScriptRuntime.java:2668)
E/TiUncaughtHandler( 427): at org.mozilla.javascript.Interpreter.do_add(Interpreter.java:3039)
E/TiUncaughtHandler( 427): at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1325)
E/TiUncaughtHandler( 427): at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
E/TiUncaughtHandler( 427): at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
E/TiUncaughtHandler( 427): at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
E/TiUncaughtHandler( 427): at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3177)
E/TiUncaughtHandler( 427): at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
E/TiUncaughtHandler( 427): at org.mozilla.javascript.Context.evaluateReader(Context.java:1142)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.kroll.KrollContext$DefaultEvaluator.evaluateFile(KrollContext.java:105)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.kroll.KrollContext.evaluateScript(KrollContext.java:306)
E/TiUncaughtHandler( 427): at org.appcelerator.titanium.kroll.KrollContext.handleEvalFile(KrollContext.java:318)
E/TiUncaughtHandler( 427): ... 5 more
E/AndroidRuntime( 427): FATAL EXCEPTION: kroll$5: app://examples/filesystem.js
E/AndroidRuntime( 427): org.mozilla.javascript.WrappedException: Wrapped java.lang.IllegalArgumentException: size < 0
E/AndroidRuntime( 427): at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1786)
E/AndroidRuntime( 427): at org.appcelerator.titanium.kroll.KrollContext$DefaultEvaluator.handleException(KrollContext.java:148)
E/AndroidRuntime( 427): at org.appcelerator.titanium.kroll.KrollContext.handleEvalFile(KrollContext.java:325)
E/AndroidRuntime( 427): at org.appcelerator.titanium.kroll.KrollContext.handleMessage(KrollContext.java:217)
E/AndroidRuntime( 427): at org.appcelerator.titanium.TiMessageQueue.handleMessage(TiMessageQueue.java:223)
E/AndroidRuntime( 427): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 427): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 427): at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:86)
E/AndroidRuntime( 427): Caused by: java.lang.IllegalArgumentException: size < 0
E/AndroidRuntime( 427): at java.io.ByteArrayOutputStream.<init>(ByteArrayOutputStream.java:65)
E/AndroidRuntime( 427): at org.appcelerator.titanium.util.TiStreamHelper.toByteArray(TiStreamHelper.java:106)
E/AndroidRuntime( 427): at org.appcelerator.titanium.TiBlob.getBytes(TiBlob.java:120)
E/AndroidRuntime( 427): at org.appcelerator.titanium.TiBlob.getText(TiBlob.java:216)
E/AndroidRuntime( 427): at org.appcelerator.titanium.TiBlob.toString(TiBlob.java:259)
E/AndroidRuntime( 427): at org.appcelerator.kroll.KrollProxy.getDefaultValue(KrollProxy.java:708)
E/AndroidRuntime( 427): at org.appcelerator.kroll.KrollObject.getDefaultValue(KrollObject.java:155)
E/AndroidRuntime( 427): at org.mozilla.javascript.ScriptRuntime.add(ScriptRuntime.java:2668)
E/AndroidRuntime( 427): at org.mozilla.javascript.Interpreter.do_add(Interpreter.java:3039)
E/AndroidRuntime( 427): at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1325)
E/AndroidRuntime( 427): at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
E/AndroidRuntime( 427): at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
E/AndroidRuntime( 427): at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
E/AndroidRuntime( 427): at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3177)
E/AndroidRuntime( 427): at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
E/AndroidRuntime( 427): at org.mozilla.javascript.Context.evaluateReader(Context.java:1142)
E/AndroidRuntime( 427): at org.appcelerator.titanium.kroll.KrollContext$DefaultEvaluator.evaluateFile(KrollContext.java:105)
E/AndroidRuntime( 427): at org.appcelerator.titanium.kroll.KrollContext.evaluateScript(KrollContext.java:306)
E/AndroidRuntime( 427): at org.appcelerator.titanium.kroll.KrollContext.handleEvalFile(KrollContext.java:318)
E/AndroidRuntime( 427): ... 5 more
W/ActivityManager( 64): Force finishing activity com.appcelerator.titanium/org.appcelerator.titanium.TiActivity
W/ActivityManager( 64): Force finishing activity com.appcelerator.titanium/ti.modules.titanium.ui.TiTabActivity
W/ActivityManager( 64): Activity pause timeout for HistoryRecord{40711420 com.appcelerator.titanium/org.appcelerator.titanium.TiActivity}
W/ActivityManager( 64): Launch timeout has expired, giving up wake lock!
W/ActivityManager( 64): Activity idle timeout for HistoryRecord{406afc58 com.appcelerator.titanium/.KitchensinkActivity}
W/ActivityManager( 64): Activity destroy timeout for HistoryRecord{406f06b0 com.appcelerator.titanium/ti.modules.titanium.ui.TiTabActivity}
W/ActivityManager( 64): Activity destroy timeout for HistoryRecord{40711420 com.appcelerator.titanium/org.appcelerator.titanium.TiActivity}
D/SntpClient( 64): request time failed: java.net.SocketException: Address family not supported by protocol
I/Process ( 427): Sending signal. PID: 427 SIG: 9
I/ActivityManager( 64): Process com.appcelerator.titanium (pid 427) has died.
It's working on 1.7.1.
Additional Problem Reports from the Community
More reports here:
http://developer.appcelerator.com/question/123092/titaniumfilesystemfile-read-does-not-work-anymore-in-172-on-android
Updated ticket so that it will receive attention.
I've attached a simple app that reproduces this trace. Simply run the app via TiStudio, or manually by command line (with an emulator running):
If the label says "Hello World. This is a filesystem read test", then it passes. Watch logcat, and if you see the trace, or if the label showsWhen testing with an empty
text.txtfile the following stacktrace was thrown.Verifying on 1_7_X and master.
Resolved. Tested On: Mac OSX Lion TiMob: 1.8.0.v20110906155354 TiStud: 1.0.5.201109091616 Devices Used: Android Emulator 2.2 Droid 1 Droid 3
Open to add tag
Tested with 1.7.3.v20110928185013 with Hero 2.1 Galaxy Tab 3.1 Emulator 2.3
Standardizing summary and labels.