Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Redundant Null Check and Dead Code
Redundant Null Check and Dead Code [message #1823098] Thu, 19 March 2020 13:30 Go to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
I have code like this:
  protected void processObject(EObject object)
  {
    if (recordAnyTypeNSDecls && object instanceof AnyType)
    {
      FeatureMap featureMap = ((AnyType)object).getAnyAttribute();
      for (Map.Entry<String, String> entry : helper.getAnyContentPrefixToURIMapping().entrySet())
      {
        Object uri = entry.getValue();
        featureMap.add(extendedMetaData.demandFeature(ExtendedMetaData.XMLNS_URI, entry.getKey(), false), uri == null ? "" : uri);
      }
    }

    if (object != null)
    {
      objects.push(object);
      types.push(OBJECT_TYPE);

      if (extendedMetaData != null)
      {
        EStructuralFeature mixedFeature = extendedMetaData.getMixedFeature(object.eClass());
        if (mixedFeature != null)
        {
          mixedTargets.push((FeatureMap)object.eGet(mixedFeature));
        }
        else
        {
          mixedTargets.push(null);
        }
      }
      else
      {
        mixedTargets.push(null);
      }
    }
    else
    {
      types.push(ERROR_TYPE);
    }
  }

It claims that "object != null" is a redundant check. But I don't think it's redundant. As a result it also complains the the final else is dead code.

Is this a regression?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Redundant Null Check and Dead Code [message #1823108 is a reply to message #1823098] Thu, 19 March 2020 14:39 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
I'm unable to reproduce due to missing context - I fail to expand the snippet into something compilable :(
Re: Redundant Null Check and Dead Code [message #1823114 is a reply to message #1823108] Thu, 19 March 2020 15:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
The attached file has the same problem. It was hard to reproduce. This file has no non-JRE dependencies. If I delete a single variable, the problem goes away. Very strange!
  • Attachment: Test.java
    (Size: 2.90KB, Downloaded 61 times)


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Redundant Null Check and Dead Code [message #1823121 is a reply to message #1823114] Thu, 19 March 2020 17:31 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The strangeness and intolerance of gratuitous variable pruning in a repro is very reminiscent of [1] which was fixed in 4.15M1.

Regards

Ed Willink

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=459397
Re: Redundant Null Check and Dead Code [message #1823131 is a reply to message #1823121] Thu, 19 March 2020 21:32 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Thanks Eds, you hit the nail: 64 variables.

Over to https://bugs.eclipse.org/561280
Previous Topic:New Resource Leak Warnings...
Next Topic:Include QuickAccess text field
Goto Forum:
  


Current Time: Thu Apr 18 23:31:55 GMT 2024

Powered by FUDForum. Page generated in 0.03939 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top