[RFC][icedtea-web] Fix usage of == -> .equals for various String comparisons

Deepak Bhole dbhole at redhat.com
Wed May 16 09:45:36 PDT 2012


* Adam Domurad <adomurad at redhat.com> [2012-05-16 12:08]:
> Thanks Jiri, Deepak, Pavel for reviewing my patch!
> 
> I have fixed the issues previously state, except for the constant extraction suggestion. 
> 
> Here are the updated Changelog and patch file.
> 

Thanks Adam.

OK from me for HEAD.

Cheers,
Deepak

> Changelog:
> 2012-05-16  Adam Domurad  <adomurad at redhat.com>
> 
> 	Fixed uses of == to compare String objects to .equals where 
> 	appropriate.
> 	Noted a non-obvious use of == to compare a 'magic' String reference.
> 	* netx/net/sourceforge/jnlp/JNLPFile.java:
> 	Changed calls that compare String contents from == to .equals
> 	* plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java: 
> 	Same
> 	* plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java:
> 	Same
> 	* netx/net/sourceforge/jnlp/Version.java: Added comment explaining why
> 	== was used vs .equals

> diff --git a/netx/net/sourceforge/jnlp/JNLPFile.java b/netx/net/sourceforge/jnlp/JNLPFile.java
> --- a/netx/net/sourceforge/jnlp/JNLPFile.java
> +++ b/netx/net/sourceforge/jnlp/JNLPFile.java
> @@ -208,7 +208,7 @@ public class JNLPFile {
>          //(i.e. If the jnlp file being launched exist locally, but it
>          //originated from a website, then download the one from the website
>          //into the cache).
> -        if (sourceLocation != null && location.getProtocol() == "file") {
> +        if (sourceLocation != null && "file".equals(location.getProtocol())) {
>              openURL(sourceLocation, version, policy);
>          }
>  
> diff --git a/netx/net/sourceforge/jnlp/SecurityDesc.java b/netx/net/sourceforge/jnlp/SecurityDesc.java
> --- a/netx/net/sourceforge/jnlp/SecurityDesc.java
> +++ b/netx/net/sourceforge/jnlp/SecurityDesc.java
> @@ -202,7 +202,7 @@ public class SecurityDesc {
>          PermissionCollection permissions = getSandBoxPermissions();
>  
>          // discard sandbox, give all
> -        if (type == ALL_PERMISSIONS) {
> +        if (ALL_PERMISSIONS.equals(type)) {
>              permissions = new Permissions();
>              if (customTrustedPolicy == null) {
>                  permissions.add(new AllPermission());
> @@ -213,7 +213,7 @@ public class SecurityDesc {
>          }
>  
>          // add j2ee to sandbox if needed
> -        if (type == J2EE_PERMISSIONS)
> +        if (J2EE_PERMISSIONS.equals(type))
>              for (int i = 0; i < j2eePermissions.length; i++)
>                  permissions.add(j2eePermissions[i]);
>  
> diff --git a/netx/net/sourceforge/jnlp/Version.java b/netx/net/sourceforge/jnlp/Version.java
> --- a/netx/net/sourceforge/jnlp/Version.java
> +++ b/netx/net/sourceforge/jnlp/Version.java
> @@ -230,6 +230,7 @@ public class Version {
>          Integer number2 = Integer.valueOf(0);
>  
>          // compare as integers
> +        // for normalization key, compare exact object, not using .equals
>          try {
>              if (!(part1 == emptyString)) // compare to magic normalization key
>                  number1 = Integer.valueOf(part1);
> @@ -242,9 +243,9 @@ public class Version {
>              // means to compare as strings
>          }
>  
> -        if (part1 == emptyString)
> +        if (part1 == emptyString) // compare to magic normalization key
>              part1 = "";
> -        if (part2 == emptyString)
> +        if (part2 == emptyString) // compare to magic normalization key
>              part2 = "";
>  
>          return part1.compareTo(part2);
> diff --git a/plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java b/plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java
> --- a/plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java
> +++ b/plugin/icedteanp/java/sun/applet/GetMemberPluginCallRequest.java
> @@ -50,7 +50,7 @@ public class GetMemberPluginCallRequest 
>          String[] args = message.split(" ");
>          // FIXME: Is it even possible to distinguish between null and void
>          // here?
> -        if (args[3] != "null" && args[3] != "void")
> +        if (!"null".equals(args[3]) && !"void".equals(args[3]))
>              object = AppletSecurityContextManager.getSecurityContext(0).getObject(Integer.parseInt(args[3]));
>          setDone(true);
>      }
> diff --git a/plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java b/plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java
> --- a/plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java
> +++ b/plugin/icedteanp/java/sun/applet/PluginCallRequestFactory.java
> @@ -41,15 +41,15 @@ public class PluginCallRequestFactory {
>  
>      public PluginCallRequest getPluginCallRequest(String id, String message, Long reference) {
>  
> -        if (id == "member") {
> +        if ("member".equals(id)) {
>              return new GetMemberPluginCallRequest(message, reference);
> -        } else if (id == "void") {
> +        } else if ("void".equals(id)) {
>              return new VoidPluginCallRequest(message, reference);
> -        } else if (id == "window") {
> +        } else if ("window".equals(id)) {
>              return new GetWindowPluginCallRequest(message, reference);
> -        } else if (id == "proxyinfo") {
> +        } else if ("proxyinfo".equals(id)) {
>              return new PluginProxyInfoRequest(message, reference);
> -        } else if (id == "cookieinfo") {
> +        } else if ("cookieinfo".equals(id)) {
>              return new PluginCookieInfoRequest(message, reference);
>          } else {
>              throw new RuntimeException("Unknown plugin call request type requested from factory");




More information about the distro-pkg-dev mailing list