RFO-BASIC / Basic

The Repository for the files the Basic project that creates the BASIC! APK for Google Play
62 stars 42 forks source link

Crash getting relative path #229

Open jMarcS opened 7 years ago

jMarcS commented 7 years ago

This is a spin-off of Issue #217, where Basic.getRelativePath(String, String) was added to support the new Program.Info command.

Editor.onResume() can call getRelativePath() with two identical paths. It happens, for example, if you are in the BASIC! Editor and you rotate the phone: after normalizing, both target and base paths are (on my Android 5.1 Moto G) "/storage/emulated/0/rfo-basic/source". The logic that constructs the common path adds "/" to every segment, so the result is "/storage/emulated/0/rfo-basic/source/". This is one character longer than the normalized target and base, so on this line

    relative.append(normalizedTargetPath.substring(common.length()));

BASIC! crashes with an IndexOutOBoundsException.

When the paths are the same, the substring() result is empty. That means I can hack a fix by adding a length condition:

    if (normalizedTargetPath.length() > common.length() ) {
        relative.append(normalizedTargetPath.substring(common.length()));
    }

I can't do more now, gotta get v01.91 onto Google Play. But some day we ought to revisit this code.

mougino commented 7 years ago

Forum user Sprougnaf discovered a crash when a program using PROGRAM.INFO is launched from ShortcutLauncher. See http://rfobasic.freeforums.org/program-info-t4972.html

Is this the same bug?

jMarcS commented 7 years ago

Released in Version 01.91, 2017/03/14. Leaving the issue open until mougino's question is resolved.