Menu

#320 RepeatedConditionals: allow calls to any methods without side effects

3.0.1
closed-fixed
None
5
2014-11-20
2014-11-11
No

This is a further enhancement for [feature-requests:#312]. As we already have the database of methods without side effects (see [feature-requests:#318]) it would be simpler and better to use it for this pattern: duplicate call to method without side effect is very unlikely to be intended.

Several new bugs found after this change is implemented:

// org.eclipse.equinox.spi.p2.publisher.PublisherHelper
public static Version fromOSGiVersion(org.osgi.framework.Version version) {
  if (version == null)
    return null;
  if (version.getMajor() == Integer.MAX_VALUE && 
      version.getMicro() == Integer.MAX_VALUE && // <<<<
      version.getMicro() == Integer.MAX_VALUE)
        return Version.MAX_VERSION;
  return Version.createOSGi(version.getMajor(), version.getMinor(),
    version.getMicro(), version.getQualifier());
}

version.getMicro() is compared two times. Seems that version.getMinor() was intended.

// org.eclipse.osgi.internal.loader.BundleLoaderSources
boolean forceSourceCreation(ModuleCapability packageCapability) {
  Map<String, String> directives = packageCapability.getDirectives();
  return directives.get(PackageNamespace.CAPABILITY_EXCLUDE_DIRECTIVE) != null ||
    directives.get(PackageNamespace.CAPABILITY_EXCLUDE_DIRECTIVE) != null;
}

The same element is fetched from the same map twice. Seems that CAPABILITY_INCLUDE_DIRECTIVE was intended.

// org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration
for (BugzillaFlag bugzillaFlag : flags) {
  if (nameValue.equals(bugzillaFlag.getName())) {
    if (nameValue.equals(bugzillaFlag.getName())) {
      ...
    }
  }
}

Not sure what was intended, but clearly a bug.

False-positives are very unlikely, but I'll test a few more projects before committing the changes.

Related

Feature Requests: #312
Feature Requests: #318

Discussion

  • Tagir Valeev

    Tagir Valeev - 2014-11-11
    • status: open-accepted --> closed-fixed
     
  • Andrey Loskutov

    Andrey Loskutov - 2014-11-20
    • Group: 3.x --> 3.0.1
     

Log in to post a comment.