From 0e76e955ba4848b18ee458cb9f53cc8e64671146 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Sun, 23 Jun 2013 17:09:52 +0200 Subject: Fix issues found by Code Analysis --- src/de/blinkt/openvpn/core/ConfigParser.java | 6 +++--- src/de/blinkt/openvpn/core/OpenVPN.java | 2 +- src/de/blinkt/openvpn/core/OpenVPNThread.java | 10 +++------- src/de/blinkt/openvpn/core/OpenVpnService.java | 20 +++++++++----------- src/de/blinkt/openvpn/core/X509Utils.java | 2 +- 5 files changed, 17 insertions(+), 23 deletions(-) (limited to 'src/de/blinkt/openvpn/core') diff --git a/src/de/blinkt/openvpn/core/ConfigParser.java b/src/de/blinkt/openvpn/core/ConfigParser.java index 3c3b37a9..1a37f7cd 100644 --- a/src/de/blinkt/openvpn/core/ConfigParser.java +++ b/src/de/blinkt/openvpn/core/ConfigParser.java @@ -3,6 +3,7 @@ package de.blinkt.openvpn.core; import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; +import java.util.Collections; import java.util.HashMap; import java.util.Locale; import java.util.Vector; @@ -64,8 +65,7 @@ public class ConfigParser { String meta = line.split("#\\sOVPN_ACCESS_SERVER_", 2)[1]; String[] parts = meta.split("=",2); Vector rval = new Vector(); - for(String p:parts) - rval.add(p); + Collections.addAll(rval, parts); return rval; } @@ -359,7 +359,7 @@ public class ConfigParser { Vector proto = getOption("proto", 1,1); if(proto!=null){ - np.mUseUdp=isUdpProto(proto.get(1));; + np.mUseUdp=isUdpProto(proto.get(1)); } // Parse remote config diff --git a/src/de/blinkt/openvpn/core/OpenVPN.java b/src/de/blinkt/openvpn/core/OpenVPN.java index 66d985bd..af090204 100644 --- a/src/de/blinkt/openvpn/core/OpenVPN.java +++ b/src/de/blinkt/openvpn/core/OpenVPN.java @@ -354,7 +354,7 @@ public class OpenVPN { // The stoned way of java to return an array from a vector // brought to you by eclipse auto complete - return (LogItem[]) logbuffer.toArray(new LogItem[logbuffer.size()]); + return logbuffer.toArray(new LogItem[logbuffer.size()]); } diff --git a/src/de/blinkt/openvpn/core/OpenVPNThread.java b/src/de/blinkt/openvpn/core/OpenVPNThread.java index 2cfde13d..100990bb 100644 --- a/src/de/blinkt/openvpn/core/OpenVPNThread.java +++ b/src/de/blinkt/openvpn/core/OpenVPNThread.java @@ -8,10 +8,7 @@ import de.blinkt.openvpn.core.OpenVPN.LogItem; import java.io.*; import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.LinkedList; -import java.util.Locale; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; public class OpenVPNThread implements Runnable { @@ -83,9 +80,8 @@ public class OpenVPNThread implements Runnable { private void startOpenVPNThreadArgs(String[] argv, Map env) { LinkedList argvlist = new LinkedList(); - - for(String arg:argv) - argvlist.add(arg); + + Collections.addAll(argvlist, argv); ProcessBuilder pb = new ProcessBuilder(argvlist); // Hack O rama diff --git a/src/de/blinkt/openvpn/core/OpenVpnService.java b/src/de/blinkt/openvpn/core/OpenVpnService.java index 230ddbaa..0bfc150a 100644 --- a/src/de/blinkt/openvpn/core/OpenVpnService.java +++ b/src/de/blinkt/openvpn/core/OpenVpnService.java @@ -68,7 +68,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac private static boolean mNotificationAlwaysVisible =false; private final IBinder mBinder = new LocalBinder(); - private boolean mOvpn3; + private boolean mOvpn3 = false; private OpenVPNManagement mManagement; @@ -269,14 +269,14 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac OpenVPN.addStateListener(this); OpenVPN.addByteCountListener(this); - if(intent != null && intent.getAction() !=null &&intent.getAction().equals(PAUSE_VPN)) + if(intent != null && PAUSE_VPN.equals(intent.getAction())) { if(mDeviceStateReceiver!=null) mDeviceStateReceiver.userPause(true); return START_NOT_STICKY; } - if(intent != null && intent.getAction() !=null &&intent.getAction().equals(RESUME_VPN)) + if(intent != null && RESUME_VPN.equals(intent.getAction())) { if(mDeviceStateReceiver!=null) mDeviceStateReceiver.userPause(false); @@ -284,12 +284,13 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac } - if(intent != null && intent.getAction() !=null &&intent.getAction().equals(START_SERVICE)) + if(intent != null && START_SERVICE.equals(intent.getAction())) return START_NOT_STICKY; - if(intent != null && intent.getAction() !=null &&intent.getAction().equals(START_SERVICE_STICKY)) { + if(intent != null && START_SERVICE_STICKY.equals(intent.getAction())) { return START_REDELIVER_INTENT; } + assert(intent!=null); // Extract information from the intent. String prefix = getPackageName(); @@ -312,6 +313,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac try { Thread.sleep(1000); } catch (InterruptedException e) { + e.printStackTrace(); } @@ -320,6 +322,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac try { Thread.sleep(1000); } catch (InterruptedException e) { + e.printStackTrace(); } } // An old running VPN should now be exited @@ -512,11 +515,6 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac } } - - public void addRoute(CIDRIP route) - { - mRoutes.add(route ); - } public void addRoute(String dest, String mask) { CIDRIP route = new CIDRIP(dest, mask); if(route.len == 32 && !mask.equals("255.255.255.255")) { @@ -537,7 +535,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac mMtu=mtu; } - public void setLocalIP(CIDRIP cdrip) + public void setLocalIP(CIDRIP cdrip) { mLocalIP=cdrip; } diff --git a/src/de/blinkt/openvpn/core/X509Utils.java b/src/de/blinkt/openvpn/core/X509Utils.java index 48434b22..ff1e932f 100644 --- a/src/de/blinkt/openvpn/core/X509Utils.java +++ b/src/de/blinkt/openvpn/core/X509Utils.java @@ -26,7 +26,7 @@ public class X509Utils { return certFact.generateCertificate(inStream); } - public static PemObject readPemObjectFromFile (String keyfilename) throws CertificateException, IOException { + public static PemObject readPemObjectFromFile (String keyfilename) throws IOException { Reader inStream; -- cgit v1.2.3