''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>


Solution 1:[1]

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-

Solution 2:[2]

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.

Solution 3:[3]

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.

Solution 4:[4]

You can try this

  1. Open or move to 'Project Panel' enter image description here
  2. Scroll down and find your library enter image description here
  3. Left click on your library enter image description here
  4. Inside the context menu, select 'Open Library Settings' enter image description here
  5. Once there, check that the binaries and sources are associated: enter image description here

Solution 5:[5]

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.

Solution 6:[6]

I had the same issue, too. The root reason is two different jar packages have some conflicts. So I solved it by removing one of the conflicting jar package.

Solution 7:[7]

I had a problem like yours today. I found that my IntelliJ was set to work with Java version 16 and my project was built in Java version 11.

To fix it, I did this: clicked on File -> Project Structure -> Project Settings -> Project, and changed "Project SDK" property to version 11.

After clicking on OK button, I didn't get the message "source code does not match bytecode" anymore.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mouse_8b
Solution 2 cb4
Solution 3 cb4
Solution 4 cb4
Solution 5 Neil Ruggiero
Solution 6 Rt.Tong
Solution 7 Dharman