gwt-syncproxy
gwt-syncproxy copied to clipboard
SyncProxy 0.5 in Android N (7.0) NullPointerException: Attempt to get length of null array
I have identified the issue when running an Application using SynxProxy 0.5 on a Nexus device running Android N. This crashes the application.
Here is what I have found up until now:
String classPath = System.getProperty("java.class.path");
returns "." i.e. root directory of the device. Which seems to be off-limits to the application in Android N.
So, when SyncProxy tries File.list(XXX)
methods in RpcPolicyFinder
- it always returns null
in Android N.
Hence, when searchPolicyFileInDirectory(String path)
is called with the following code:
public static Map<String, String> searchPolicyFileInDirectory(String path) {
Map<String, String> result = new HashMap<String, String>();
String policyName = null;
File f = new File(path);
String[] children = f.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.endsWith(GWT_PRC_POLICY_FILE_EXT)) {
return true;
}
return false;
}
});
// The children is always `null` - in Android N. So accessing the children using:
for (String child : children) {
// Will cause NullPointerException: Attempt to get length of null array
[...]
}
I have tested this on Android 4.4, Android 5.0.1, Android 5.1.1, Android 6.0 - these versions do not have the same problem. Only Android 7.0
Options to resolve this further is to pass through the application directory to the Library someway and then use this to list the gwt.rpc files.
I have not yet investigated which permissions could resolve the issue. While not an ideal solution, I have used a simple check if(children!=null)
to workaround the problem in my code as I do not store the gwt.rpc files in my application.
Getting the same error. Can u tell me more precisely about how to work around this error?
This is how my RpcPolicyFinder.java
looks like now in SyncProxy-Android
project.. I downloaded the sources and added the check I mentioned above (see code).
There is a possibility that there are File permissions which can be set which avoids this issue. I didn't get a chance to test them out. If you are successful in this approach, we would much appreciate you updating this issue.
public static Map<String, String> searchPolicyFileInDirectory(String path) {
Map<String, String> result = new HashMap<String, String>();
String policyName = null;
File f = new File(path);
String[] children = f.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.endsWith(GWT_PRC_POLICY_FILE_EXT)) {
return true;
}
return false;
}
});
if(children!=null) {
for (String child : children) {
policyName = child.substring(0, child.length()
- GWT_PRC_POLICY_FILE_EXT.length());
try {
result.putAll(parsePolicyName(policyName, new FileInputStream(
new File(path, child))));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
return result;
}
Thanks for instant reply. :D I will try it out.
I have the same problem, It runs below nougat version, please someone help
Two things to try:
-
See if you are able to set Files Read permission -
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
in AndroidManifest.xml see if it fixes the issue. If it does, please do report back here. -
Try the code above.