Using a shared project library in multiple modules is shown by IDEA as an error

Is there something I don't understand or is this a bug in IDEA? I have two modules in the project and both of them are using using the Hibernate library.

In the code I am saying something like:

SessionFactoryUtils.getSession(sessionFactory, true);

IDEA marks the statement as an error. It says: "getSession(net.sf.hibernate SessionFactory, boolean) in SessionFactoryUtils cannot be applied to getSession(net.sf.hibernate SessionFactory, boolean)"

So as you can see, IDEA is saying that instead of using class A as a parameter, you should be using class A. That seems like an error to me.

Even if there are no dependenices between the two projects, IDEA marks that statement as an error. The only way to fix this is to import the resource as a module library, not a class library. But isn't it the whole point of project libraries to be able to use them in multiple modules?

Everything compiles alright and it seems that the only problem is with method calls that take the problematic classes as parameters. It is just very annoying that IDEA shows that part of the code as an error.

3 comments
Comment actions Permalink

The problem actually isn't as simple as I stated before. It seems that the error will not occur for methods defined in your module. To demonstrate the error, you will need to be using two libraries that interact. In my case Spring and Hibernate, but any libraries where one manipulates the objects of another should do.

So I have both Spring and Hibernate as project modules and my two modules (M1 and M2) are using them. Now in module M1 I can't use any of the Spring's methods that manipulate Hibernate objects. If I say that M2 doesn't use the Hibernate library, M1's code will no longer be considered an error by IDEA.

It seems that the problem also affects the return values of methods, not only the parameters. For example statement..

Session session = holder.getSession();

.. is considered an error by IDEA. It says: "Incompatible types. Found: 'net.sf.hibernate.Session', required 'net.sf.hibernate.Session'."

The problem isn't only cosmetic, because it basically makes it almost impossible to develop such a code with IDEA as the code analysis functionality will stop working for the statements and all the variables related to them. Also it is difficult to separate the imaginary errors from real errors in the code.

I would appreciate any help or ideas on how to solve this. Also if this really is a bug, feel free to ask more information in order to get this annoying issue fixed.

0
Comment actions Permalink

Markus Halttunen wrote:

The problem actually isn't as simple as I stated before. It seems that the error will not occur for methods defined in your module. To demonstrate the error, you will need to be using two libraries that interact. In my case Spring and Hibernate, but any libraries where one manipulates the objects of another should do.

So I have both Spring and Hibernate as project modules and my two modules (M1 and M2) are using them. Now in module M1 I can't use any of the Spring's methods that manipulate Hibernate objects. If I say that M2 doesn't use the Hibernate library, M1's code will no longer be considered an error by IDEA.

It seems that the problem also affects the return values of methods, not only the parameters. For example statement..

Session session = holder.getSession();

. is considered an error by IDEA. It says: "Incompatible types. Found: 'net.sf.hibernate.Session', required 'net.sf.hibernate.Session'."

The problem isn't only cosmetic, because it basically makes it almost impossible to develop such a code with IDEA as the code analysis functionality will stop working for the statements and all the variables related to them. Also it is difficult to separate the imaginary errors from real errors in the code.

I would appreciate any help or ideas on how to solve this. Also if this really is a bug, feel free to ask more information in order to get this annoying issue fixed.


I've somewhat lost in this dependency descriptions. Would you please
mail .ipr and .iml files to me?


--
Maxim Shafirov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

I also hit this problem when using 4.5.1 with multiple modules - but against our own in house source code, not 3rd party libs.

0

Please sign in to leave a comment.