Bug 102534 - [refactoring] Inline method: Null pointer exception
Summary: [refactoring] Inline method: Null pointer exception
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Dirk Baeumer CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-01 16:32 EDT by Trevor Robinson CLA Friend
Modified: 2005-08-09 09:59 EDT (History)
0 users

See Also:


Attachments
Code patch (1.43 KB, patch)
2005-07-11 11:05 EDT, Dirk Baeumer CLA Friend
no flags Details | Diff
Additional test resources (2.42 KB, patch)
2005-07-11 11:06 EDT, Dirk Baeumer CLA Friend
no flags Details | Diff
Additional test methods (2.42 KB, patch)
2005-07-11 11:07 EDT, Dirk Baeumer CLA Friend
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Trevor Robinson CLA Friend 2005-07-01 16:32:21 EDT
Trying to inline:

    DirectedExpect addRespExpect(
        final GlobalTxnRecord txn,
        final PktNodeInfo fromNode,
        final PktNodeInfo toNode,
        final String description,
        final RoutedPacket pkt,
        final BitVector matchBits,
        final BitVector checkBits,
        final PacketHandler destHandler)
    {
        final DirectedExpect expect = new DirectedExpect(expectMgr, txn,
            fromNode, toNode, description, pkt, matchBits, destHandler);
        expect.setCheckPacket(checkBits);
        expect.activate();
        return expect;
    }

into:

    final PacketHandler srcRespHandler = new PacketHandler()
    {
        public void execute(final FullExpect expect, final PacketRecord pktRec)
        {
            final GlobalTxnRecord txn = expect.getTxn();
            if (pktRec.toNode.contains(txn.tgtNode))
            {
                // ...
            }
            else
            {
                final DirectedPacket fwdPkt;
                final PktNodeInfo localTgtNode;
                final BitVector matchBits;
                // ...
                addRespExpect(txn, pktRec.toNode, localTgtNode,
                    "forwarded source response", fwdPkt, matchBits, null, this);
            }
        }
    };

results in:

Error 2005-07-01 15:21:42.842 Internal Error
java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:327)
at
org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.run(RefactoringWizardDialog2.java:293)
at
org.eclipse.ltk.ui.refactoring.RefactoringWizard.internalPerformFinish(RefactoringWizard.java:547)
at
org.eclipse.ltk.ui.refactoring.UserInputWizardPage.performFinish(UserInputWizardPage.java:153)
at
org.eclipse.ltk.ui.refactoring.RefactoringWizard.performFinish(RefactoringWizard.java:613)
at
org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.okPressed(RefactoringWizardDialog2.java:417)
...
Caused by: java.lang.NullPointerException
at
org.eclipse.jdt.internal.corext.refactoring.code.CallInliner.replaceCall(CallInliner.java:599)
at
org.eclipse.jdt.internal.corext.refactoring.code.CallInliner.perform(CallInliner.java:471)
at
org.eclipse.jdt.internal.corext.refactoring.code.InlineMethodRefactoring.checkFinalConditions(InlineMethodRefactoring.java:238)
at
org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:84)
at
org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:114)
at
org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:189)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1719)
at
org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:86)
at
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)

eclipse.buildId=I20050627-1435
java.version=1.5.0_02
java.vendor=Sun Microsystems Inc.
Comment 1 Dirk Baeumer CLA Friend 2005-07-02 13:29:57 EDT
To investigate for 3.1.1.
Comment 2 Dirk Baeumer CLA Friend 2005-07-11 09:59:42 EDT
Trevor,

I tried to reproduce the problem using the test case below and generated stubs
for the additional types. However, I was not able to produce the NPE. Do you
still have the code around. Can you provide the complete code of the else part
of the outer if statement that contains the call to addRespExpect. There must be
something that got replaced by //... that causes the refactoring to misinterpret
the context.

package p102534;

public class TestCase {
	private Manager expectMgr;
	
    DirectedExpect addRespExpect(
            final GlobalTxnRecord txn,
            final PktNodeInfo fromNode,
            final PktNodeInfo toNode,
            final String description,
            final RoutedPacket pkt,
            final BitVector matchBits,
            final BitVector checkBits,
            final PacketHandler destHandler)
        {
            final DirectedExpect expect = new DirectedExpect(expectMgr, txn,
                fromNode, toNode, description, pkt, matchBits, destHandler);
            expect.setCheckPacket(checkBits);
            expect.activate();
            return expect;
        }

    private void testCase() {
        final PacketHandler srcRespHandler = new PacketHandler()
        {
            public void execute(final FullExpect expect, final PacketRecord pktRec)
            {
                final GlobalTxnRecord txn = expect.getTxn();
                if (pktRec.toNode.contains(txn.tgtNode))
                {
                    // ...
                }
                else
                {
                    final DirectedPacket fwdPkt= null;
                    final PktNodeInfo localTgtNode= null;
                    final BitVector matchBits= null;
                    // ...
                    addRespExpect(txn, pktRec.toNode, localTgtNode,
                        "forwarded source response", fwdPkt, matchBits, null, this);
                }
            }
        };    	
    }
}
Comment 3 Dirk Baeumer CLA Friend 2005-07-11 10:10:12 EDT
I think I found it. Could it be that there was a label in front of the
addRespExpect call ?
Comment 4 Dirk Baeumer CLA Friend 2005-07-11 11:03:50 EDT
The full fix is too risky for 3.1.1. The problem is that not all statements can
be  labeled. For example a local declaration can't be labeled. The fix for 3.1.1
will be to introduce a block like in other control statements that can have a
single statement as a body.
Comment 5 Dirk Baeumer CLA Friend 2005-07-11 11:05:59 EDT
Created attachment 24543 [details]
Code patch
Comment 6 Dirk Baeumer CLA Friend 2005-07-11 11:06:50 EDT
Created attachment 24544 [details]
Additional test resources
Comment 7 Dirk Baeumer CLA Friend 2005-07-11 11:07:38 EDT
Created attachment 24545 [details]
Additional test methods
Comment 8 Dirk Baeumer CLA Friend 2005-07-26 11:32:23 EDT
Fix reviewed by Martin Aeschlimann and Tom Eicher. Fix released for 3.1.1.
Opened PR 105168 to track the issue in the 3.2 stream.
Comment 9 Dirk Baeumer CLA Friend 2005-07-26 11:33:06 EDT
Added two additional test cases TestLabelOne and TestLabelTwo.
Comment 10 Martin Aeschlimann CLA Friend 2005-08-09 09:46:51 EDT
start verifying...
Comment 11 Martin Aeschlimann CLA Friend 2005-08-09 09:59:40 EDT
verified in I20050808-2000 (3.2) and M20050804-1200 (3.1.1)