Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Source code does not match the bytecode' use IDEA debug JdbcTemplate

When I debug the JdbcTemplate sourcecode use IDEA,the IDE tips me:'Source code does not match the bytecode'

Screenshot:

enter image description here

and i use mvn to manage my project;my maven pom config is:

<dependency>
                <groupId>org.springframework</groupId>
                <artifactId>org.springframework.orm</artifactId>
                <version>3.0.5.RELEASE</version>
  </dependency>
like image 417
guruboy Avatar asked Aug 22 '17 02:08

guruboy


4 Answers

This can also happen if you have multiple dependencies that themselves have different versions of the same dependency. This post on the JetBrains site shows how to enable the alternate source switcher in preferences.

https://intellij-support.jetbrains.com/hc/en-us/community/posts/206822215-what-does-Choose-Sources-do-and-how-can-I-undo-what-it-does-

like image 80
mouse_8b Avatar answered Nov 06 '22 14:11

mouse_8b


Intellij gives a such warning when compiled code doesn't match the source code, i.e. you try to debug the code but it has changed and not rebuilt.

Make sure after you imported your code you didn't modify it. If you modify then first build/compile it before starting the debugger.

For example below code will cause this warning :-

    public class HelloSO {
    public static void main(String[] args) {
        System.out.println("First time source code");
    }
  }

Now you compiled above class and start debugging it, everything works fine.

But after that you add one more print statement and try to put the debug point on that line without re-compile it, then in this case as byte code for new line is not generated, hence you will get same warning from IntelliJ.

like image 30
Amit Avatar answered Nov 06 '22 14:11

Amit


After viewing the other similar questions and answers on this problem, none of which helped me. What solved the problem was simply adding a dependency. In my case I ran into this issue when I was attempting to debug org.springframework.web.servlet.DispatcherServlet. I finally noticed that IntelliJ could not find javax.servlet in my imports.

In my Maven project, I added

<dependency>
  <groupId>javax</groupId>
  <artifactId>javaee-api</artifactId>
  <version>8.0.1</version>
</dependency>

to my pom.xml which solved the problem.

Double check that all of your imports are being resolved.

like image 2
Spencer Stewart Avatar answered Nov 06 '22 14:11

Spencer Stewart


For me this issue was arising because I'd made changes to my source code but had not yet deployed them to the target device. It still allowed me to set up the debugging which was confusing, but then gave me this error.

To fix:

  1. Rebuild your project / module
  2. Redeploy to your target device
  3. Run the debugger

After rebuilding / redeploying, your debug and deployed code will match up and you shouldn't get any more errors! Just a matter of matching up the two binaries.

like image 1
Neil Ruggiero Avatar answered Nov 06 '22 13:11

Neil Ruggiero