IDEA is optimizing a used (?) import

A project has the following Maven dependencies (apart from JUnit):

  • org.easymock:easymock:2.4
  • org.easymock:easymockclassextension:2.4


One of the tests (greatly simplified ;)) looks like this:


import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

public class AppTest {
    @Test
    public void someTest() {
        List mock = createMock(ArrayList.class);
    }
}


IDEA is marking the line "import static org.easymock.classextension.EasyMock.*;" as an unused import statement, and suggests to optimize it.
Accepting this suggestion makes the test fail (with an error), since this will cause a different createMock() method to be used - specifically, one that cannot mock classes, only interfaces.

The JLSv3 section 7.5 is not very clear to me regarding this specific case.
Is this indeed a bug in the resolve machinery of IDEA?
(using #103.14 EAP)

-tt

5 comments
Comment actions Permalink

You mean before optimizing imports javac resolved the 'createMock' method  to the org.easymock.classextension.EasyMock class?
It shoud not be the case.
The method should resolve to the first staticly imported class, in this case org.easymock.EasyMock.

--regards,
Alexey Kudravtsev

0
Comment actions Permalink

You mean before optimizing imports javac resolved the 'createMock' method  to the org.easymock.classextension.EasyMock class?
It shoud not be the case.


That is indeed what I observe (using javac from JDK 1.6.0_23).

The method should resolve to the first staticly imported class, in this case org.easymock.EasyMock.


Which part of the spec dictates this?
Are you referring to the clause "A static-import-on-demand declaration never causes any other declaration to be shadowed" from JLS 7.5.4?

-tt
0
Comment actions Permalink

You are right, I cannot find the place in the spec which covers this situation.
But  javac always prefers the static method from the derived class.
Could you please create the issue so that I can try to fix this in IDEA?

0
Comment actions Permalink

Hi Alexey,

It's submitted already, and assigned to you as well :)
http://youtrack.jetbrains.net/issue/IDEA-64926

Kind regards,
Taras

0
Comment actions Permalink

Ahh right, thank you.

0

Please sign in to leave a comment.