Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning a variable to this and calling an inaccessible method should fail #149

Open
khatchad opened this issue Apr 29, 2016 · 5 comments
Labels
Milestone

Comments

@khatchad
Copy link
Member

khatchad commented Apr 29, 2016

Looks like my fixes from yesterday are actually not complete. Related to #144 and #141. Here's the example:

Before

package p;

interface I {
    void m(); 
}

abstract class A implements I {
    void n() {
    }

    public void m() {
        A a = this;
        a.n();
    }
}

After

package p;

interface I {
    default void m() {
        A a = this;
        a.n();
    }
}

abstract class A implements I {
    void n() {
    }
}

Discussion

this is no longer of compile-time type A but now I. This (no pun intended) should be a situation taken care of by the Pull Up refactoring that we are building our refactoring on via type constraints, but I have a feeling that we'll have the same problem there as the Eclipse implementation of Pull Up does not seem to use type constraints for preconditions.

-- Error Log from JUnit —

Class: edu.cuny.citytech.defaultrefactoring.ui.tests.MigrateSkeletalImplementationToInterfaceRefactoringTest
Method: testMethodThatAccessesPublicInstanceMethodOfTheSourceType5
Actual: null
Expected: null
Stack Trace:
junit.framework.AssertionFailedError: Precondition was supposed to fail.
    at junit.framework.Assert.fail(Assert.java:57)
    at junit.framework.Assert.assertTrue(Assert.java:22)
    at junit.framework.TestCase.assertTrue(TestCase.java:192)
    at edu.cuny.citytech.refactoring.common.tests.RefactoringTest.assertFailedPrecondition(RefactoringTest.java:37)
    at edu.cuny.citytech.refactoring.common.tests.RefactoringTest.assertFailedPrecondition(RefactoringTest.java:49)
    at edu.cuny.citytech.refactoring.common.tests.RefactoringTest.helperFail(RefactoringTest.java:122)
    at edu.cuny.citytech.refactoring.common.tests.RefactoringTest.helperFail(RefactoringTest.java:162)
    at edu.cuny.citytech.defaultrefactoring.ui.tests.MigrateSkeletalImplementationToInterfaceRefactoringTest.testMethodThatAccessesPublicInstanceMethodOfTheSourceType5(MigrateSkeletalImplementationToInterfaceRefactoringTest.java:1029)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at junit.framework.TestCase.runTest(TestCase.java:176)
    at junit.framework.TestCase.runBare(TestCase.java:141)
    at junit.framework.TestResult$1.protect(TestResult.java:122)
    at junit.framework.TestResult.runProtected(TestResult.java:142)
    at junit.framework.TestResult.run(TestResult.java:125)
    at junit.framework.TestCase.run(TestCase.java:129)
    at junit.extensions.TestDecorator.basicRun(TestDecorator.java:23)
    at junit.extensions.TestSetup$1.protect(TestSetup.java:23)
    at junit.framework.TestResult.runProtected(TestResult.java:142)
    at junit.extensions.TestSetup.run(TestSetup.java:27)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:131)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
    at org.eclipse.pde.internal.junit.runtime.PlatformUITestHarness$1.run(PlatformUITestHarness.java:47)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4024)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3700)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
    at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.runApp(NonUIThreadTestApplication.java:54)
    at org.eclipse.pde.internal.junit.runtime.UITestApplication.runApp(UITestApplication.java:47)
    at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.start(NonUIThreadTestApplication.java:48)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
@khatchad khatchad added this to the Preconditions milestone Apr 29, 2016
@khatchad khatchad added the bug label Apr 29, 2016
@khatchad
Copy link
Member Author

A similar example with the Pull Up refactoring produces an error. Here's the input example:

package p;

class I {
}

class A extends I {
    void n() {
    }

    public void m() {
        A a = this;
        a.n();
    }
}

The error produced says that one of the methods is not accessible.

@khatchad
Copy link
Member Author

But, as I thought, it also gives an error with this input where it shouldn't:

package p;

class I {
}

class A extends I {
    void n() {
    }

    public void m() {
        A a = new A();
        a.n();
    }
}

This is the same issue we had with #144.

@khatchad
Copy link
Member Author

@khatchad
Copy link
Member Author

You need type constraints here to solve this problem.

khatchad pushed a commit that referenced this issue May 17, 2016
Weird that the FIXME comment said that it should pass when in fact it
was a passing test.
khatchad pushed a commit that referenced this issue May 17, 2016
khatchad pushed a commit that referenced this issue May 27, 2016
Forgot about constructor calls. Treated those as method invocations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant