14

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>
cb4
  • 6,689
  • 7
  • 45
  • 57
guruboy
  • 359
  • 2
  • 3
  • 7

7 Answers7

6

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-

mouse_8b
  • 514
  • 5
  • 8
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.

cb4
  • 6,689
  • 7
  • 45
  • 57
Amit
  • 30,756
  • 6
  • 57
  • 88
  • I am not modifying anything and still getting that message on `oracle.ucp.jdbc.PoolDataSourceImpl`... The source code is decompiled by IntelliJ from class files. So no modification at all. – nephewtom Jul 24 '19 at 12:23
  • @nephewtom is this class coming from the new jar which you added recently ? – Amit Jul 25 '19 at 04:26
  • Not really... it is just happens in jars added from Maven dependencies. It happens for classes belonging to Oracle UCP jar and classes from MyBatis jar. I guess it is a IntelliJ issue, that gets confused and shows that message. – nephewtom Jul 25 '19 at 12:03
  • @nephewtom, did you kill any process on the taskbar of intellij – Amit Jul 25 '19 at 13:25
  • I do not really know what you mean by "the taskbar of intellij"... but I do not kill or close anything. I just use the debugger. Sometimes happens, sometimes doesn't... With the same classes and without recompiling anything. – nephewtom Jul 25 '19 at 15:52
2

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.

cb4
  • 6,689
  • 7
  • 45
  • 57
1

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
cb4
  • 6,689
  • 7
  • 45
  • 57
0

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.

Neil Ruggiero
  • 330
  • 3
  • 4
  • 11
0

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.

Rt.Tong
  • 196
  • 3
  • 5
0

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Bruno
  • 1