Debug steps into .jars when source/.jars overlap

Hello,

We are working with an large, legacy codebase (~20k Java files). For reasons I won't get into, we have the requirement that the source code and the .jars on the classpath overlap; that is to say, foo.jar will be on the classpath while com/company/foo/*.java may or not be part of a developer's sandbox.

I am trying to create an IntelliJ project that allows this scenario. I realize this is non-standard, and we are working towards modularizing our source code to bring it in line with best practices, but please bear with me. :) When I create a module that contains

<Module source> (module source containing com.company.foo)
foo.jar (a single entry module library)

then everything works fine -- I can compile, and I can debug properly. However, when I create a module that contains the following,

<Module source> (module source containing com.company.foo)
libs (a library that contains foo.jar among others)

then I can compile, but when I debug, IntelliJ consistently chooses to step into the decompiled class stub of com.company.foo rather than into the source. When I do the following:

<Module source>
libs (a library that contains foo.jar among others)
   + Attach source of com.company.foo

then debugging works perfectly (stepping stays in the source), but then any compilation is disabled for com.company.foo -- presumably because IntelliJ assumes that you never want to compile source that's attached to a library.

Is there any way to get IntelliJ to do what I am trying to do? Is there a specific reason that it behaves differently in the first scenario (overlapping source and .jar files) than in the second (overlapping source and libary)?

Thanks very much for your help,
Jared

6 comments
Comment actions Permalink

Any thoughts out there?

Thanks,
Jared

0
Comment actions Permalink

Hi Jared,

I'm afraid I don't quite understand the problem. Can you provide minimal but comlete standalone project that illustrates it?

Denis

0
Comment actions Permalink

Of course. Attached is a minimal project that demonstrates the issue. An important note that I should mention is that the issue *only* occurs when you do remote debugging; it does not occur if you start the JVM from within IntelliJ. Here are the steps:

1. Unpack the attached zip file into your IdeaProjects directory. This contains two source files, Inner.java and Outer.java, which are also both compiled and contained in lib\test.jar.
2. Open the project in IDEA.
3. Make sure there is a breakpoint on line 25 of Outer.java ("new Inner()").
4. Open a command prompt window and run the program externally by going to IdeaProjects\Test and executing the run.bat file. This should start a Java application that is listening for a debugger.
5. Back in IDEA, select the "Remote" run configuration and press the debug button.
6. Click the "Click me" button in the Java application. IDEA should stop at the "new Inner()" line breakpoint.
7. Press the "Step Into" button.

At this point, note that IDEA steps into Inner contained in the .jar, showing the decompiled stub, rather than the one in your source -- even though the out\Production\Test directory appears on the classpath before test.jar (as evidenced by run.bat).

As I mentioned before, note that this does not happen if

(1) you start the program from within IntelliJ, rather than via remote debugging;
(2) or you add test.jar as a single-entry .jar, rather than as part of a library.

Thanks for your help!

Jared



Attachment(s):
Test.zip
0
Comment actions Permalink

Hi Jared,

Just checked that against the latest 10.5 EAP build (106.561) and everything works as expected, i.e. source class was used during the stepping.

Generally, that depends on the following:

1. Correct classpath should be defined for the target run configuration:
run-configuration-classpath-setup.png
2. Make sure that module sources entry is located before the compiled classes:
module-classpath-setup.png

Denis

0
Comment actions Permalink

Brilliant! This option ("Search sources..." in the Remote run configuration) was exactly what I was needed. It works perfectly now.

Thank you, Denis, for your rapid feedback and solution to this!

Jared

0
Comment actions Permalink

Apologies for commenting on such an old thread, but I am facing this, or a very related problem, on a large multi module project I'm working on.

When selecting the search sources option <whole project> in my run configuration, the defualt behaviour seems to choose jars to step into, over locally available source. The opposite should be the default behaviour in my opinion.

To fix this, I must pick one module from my project, and add the module dependencies I want the debugger to step into. I must then point my remote config to search for sources in that module.

I've just recently commented on a Satck Overflow on this:
http://stackoverflow.com/questions/18992181/intellij-idea-breakpoints-stop-in-jars-instead-of-source-code-of-my-project

0

Please sign in to leave a comment.