Can't step into code in debugger
Answered
I have not been able to step into my project's code for some time. When I step into the code from the the test it goes to the first line. Then if I click "step over" it jumps to the method signature line then back to the unit test. I get the message "Source code does not match the byte code" when stepping into the method.
Things I have tried:
- mvn clean install -DskipTests from command line
- Invalidate cache
- Maven re-import
- File > Synchronize
I'm sure the problem is what the error message says it is. I'm just having a problem getting it so that my byte code DOES match the source code.
Please sign in to leave a comment.
>I get the message "Source code does not match the byte code" when stepping into the method.
Building by Maven may cause it. Try to rebuild (Build | Rebuild Project) the project from IDE before running tests.
I forgot to mention that I did try that as well. I get a clean build from the command line, but I get 2 errors when I rebuild the project in IntelliJ. They are both regarding a package that it says does not exist, although it appears in 8 other locations that don't cause those errors to appear.
The Source code does not match the byte code error is reported when the bytecode of the compiled class which IDE loads to the class path (IDE loads to the classpath the classes from the modules's compiler output directory + the module's dependencies (libraries and other module's output directories)) does not match with the source code you have opened in Editor. This can happen when you build the code externally, not by IDE. Perhaps Maven project structure (directories layout) is different than IDE's (i.e. there is some misconfiguration) or Maven produces different bytecode than the compiler which is used in IDE (i.e. some additional configuration with bytecode instrumentation is used). To fix it you must make sure that the maven builds the class you have opened in Editor the same way and places it into the same location as does IDE builder or build the project sources by IDE builder.
>They are both regarding a package that it says does not exist, although it appears in 8 other locations that don't cause those errors to appear.
Where these symbols are located in project? Are those from libraries or other module's dependencies? Can you navigate to them via Navigate | Class? Can you provide a sample project to check the configuration?
I tried opening up the pom.xml file again and re-importing it as a new project and was able to get a clean build within IntelliJ. Perhaps the classpath had some issues in the previous setup?
I still cannot step into the code even though I get a clean compile, and I no longer see the message that the source code does not match the bytecode.
A co-worker mentioned, however, that he gets this behavior whenever he uses a @SpyBean, which is what I am using. He says that he just needs to insert logging statements to debug rather than stepping through the code. That has been my experience too.
So you only get this with the SpyBean? Can you show it on the example and what really happens?
I was going to make a screencast, but my screencast software does not work on Mojave. But I realized that my test does not need @SpyBean, so I changed it to @Autowired and I am able to step through each line of code as I normally would.
A sample code would help to better understand how exactly annotation is used and why it may not work.
How's it possible people accepting an IDE appropriating their source code that way they cannot compile any standard application with a standard tool in a standard way without it breaking up?