jadx icon indicating copy to clipboard operation
jadx copied to clipboard

[core] Code is incorrectly placed inside `if` body block

Open bagipro opened this issue 2 years ago • 0 comments

Hey @skylot,

Please check the attached file in class com.samsung.android.support.senl.nt.base.common.util.UriFileUtils:

    public static int saveUriToFile(Context context, Uri uri, File file, long j) {
        FileOutputStream fileOutputStream;
        HttpURLConnection httpURLConnection;
        Exception e;
        InputStream inputStream;
        InputStream inputStream2 = null;
        try {
            try {
                if ("content".equals(uri.getScheme())) {
                    inputStream = context.getContentResolver().openInputStream(uri);
                } else if ("file".equals(uri.getScheme())) {
                    inputStream = getInputStreamFromFileUri(uri);
                } else {
                    if (uri.getScheme().startsWith("http")) { // <<<<<<<<<<<<<<<<<
                        HttpURLConnection connectURL = connectURL(uri.toString());
                        if (connectURL != null) {
                            try {
                                inputStream = getInputStreamFromHttpConn(connectURL, 5000);
                                httpURLConnection = connectURL;
                            } catch (Exception e2) {
                                e = e2;
                                fileOutputStream = null;
                                httpURLConnection = connectURL;
                                try {
                                    LoggerBase.m3230e("UriFileUtils", "saveUriToFile, ", e);
                                    deleteFile(file, "File downloading is stopped. Delete the temp file.");
                                    if (inputStream2 != null) {
                                    }
                                    if (fileOutputStream != null) {
                                    }
                                    if (httpURLConnection != null) {
                                    }
                                    return 1;
                                } catch (Throwable th) {
                                    th = th;
                                    if (inputStream2 != null) {
                                        try {
                                            inputStream2.close();
                                        } catch (IOException e3) {
                                            LoggerBase.m3231e("UriFileUtils", "saveUriToFile, IOException Fail to close " + e3.getMessage());
                                            if (httpURLConnection != null) {
                                            }
                                            throw th;
                                        }
                                    }
                                    if (fileOutputStream != null) {
                                        fileOutputStream.close();
                                    }
                                    if (httpURLConnection != null) {
                                        httpURLConnection.disconnect();
                                    }
                                    throw th;
                                }
                            } catch (Throwable th2) {
                                th = th2;
                                fileOutputStream = null;
                                httpURLConnection = connectURL;
                                if (inputStream2 != null) {
                                }
                                if (fileOutputStream != null) {
                                }
                                if (httpURLConnection != null) {
                                }
                                throw th;
                            }
                        } else {
                            httpURLConnection = connectURL;
                            inputStream = null;
                        }
                    } else {
                        LoggerBase.m3231e("UriFileUtils", "no handle to get file scheme : " + uri.getScheme());
                        inputStream = null;
                        httpURLConnection = null;
                    }
                    if (inputStream != null) {
                        LoggerBase.m3231e("UriFileUtils", "saveUriToFile, can not open input stream.");
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (IOException e4) {
                                LoggerBase.m3231e("UriFileUtils", "saveUriToFile, IOException Fail to close " + e4.getMessage());
                            }
                        }
                        if (httpURLConnection != null) {
                            httpURLConnection.disconnect();
                        }
                        return 1;
                    }
                    fileOutputStream = new FileOutputStream(file);
                    long j2 = 0;
                    try {
                        byte[] bArr = new byte[8192];
                        while (true) {
                            int read = inputStream.read(bArr);
                            if (read > 0) {
                                int max = Math.max(0, read);
                                j2 += max;
                                if (j2 > j) {
                                    break;
                                }
                                fileOutputStream.write(Arrays.copyOfRange(bArr, 0, max));
                            } else {
                                if (inputStream != null) {
                                    try {
                                        inputStream.close();
                                    } catch (IOException e5) {
                                        LoggerBase.m3231e("UriFileUtils", "saveUriToFile, IOException Fail to close " + e5.getMessage());
                                    }
                                }
                                fileOutputStream.close();
                                if (httpURLConnection == null) {
                                    return 0;
                                }
                                httpURLConnection.disconnect();
                                return 0;
                            }
                        }
                    } catch (Exception e6) {
                        e = e6;
                        inputStream2 = inputStream;
                        LoggerBase.m3230e("UriFileUtils", "saveUriToFile, ", e);
                        deleteFile(file, "File downloading is stopped. Delete the temp file.");
                        if (inputStream2 != null) {
                            try {
                                inputStream2.close();
                            } catch (IOException e7) {
                                LoggerBase.m3231e("UriFileUtils", "saveUriToFile, IOException Fail to close " + e7.getMessage());
                                if (httpURLConnection != null) {
                                    httpURLConnection.disconnect();
                                }
                                return 1;
                            }
                        }
                        if (fileOutputStream != null) {
                            fileOutputStream.close();
                        }
                        if (httpURLConnection != null) {
                        }
                        return 1;
                    } catch (Throwable th3) {
                        th = th3;
                        inputStream2 = inputStream;
                        if (inputStream2 != null) {
                        }
                        if (fileOutputStream != null) {
                        }
                        if (httpURLConnection != null) {
                        }
                        throw th;
                    }
                }
                if (inputStream != null) {
                }
            } catch (Exception e8) {
                e = e8;
                fileOutputStream = null;
            } catch (Throwable th4) {
                th = th4;
                fileOutputStream = null;
            }
            httpURLConnection = null;
        } catch (Exception e9) {
            e = e9;
            httpURLConnection = null;
            fileOutputStream = null;
        } catch (Throwable th5) {
            th = th5;
            httpURLConnection = null;
            fileOutputStream = null;
        }
    }

I think the code should be:

                if ("content".equals(uri.getScheme())) {
                    inputStream = context.getContentResolver().openInputStream(uri);
                } else if ("file".equals(uri.getScheme())) {
                    inputStream = getInputStreamFromFileUri(uri);
                } else if (uri.getScheme().startsWith("http")) {
                    HttpURLConnection connectURL = connectURL(uri.toString());
                    //...
                    inputStream = getInputStreamFromHttpConn(connectURL, 5000);
                }
                //...
                fileOutputStream = new FileOutputStream(file);

https://drive.google.com/file/d/1hKiiJYQjWMWKRz9yH-7DlHrFycUecCMm/view?usp=sharing

bagipro avatar Apr 20 '22 15:04 bagipro