Can we debug classes present in rt.jar? - java

I have atteched the source file to project. I want to debug a method of say ArrayList. I placed a breakpoint also in that method but on debugging it gives error -unable to install breakpoint in eclipse due to missing line number attributes.Its a desktop application.

Use the JDK system library instead of the JRE, the latter isn't compiled with the necessary debugging information.

Related

While debugging a Java program in IntelliJ, how to show Bytecode that is being executed?

I am using IntelliJ to debug a Java program. In my current case that happens to be IntelliJ itself -- to debug a problem in it -- but a similar problem occurred in the past with other code.
While single-stepping, at a certain point when stepping into a method, IntelliJ won't show the code that is being executed anymore. I am used to stepping through decompiled byte code when source is not available, but in this case IntelliJ won't show anything -- no source code, no byte code, nothing. This happens when stepping from RemoteExternalSystemProjectResolverImpl into GradleProjectResolver.
Quite suspiciously, the problem happens exactly when stepping from a class that comes from an UrlClassLoader, into a class from a PluginClassLoader.
I'm aware that the debugger will have problems associating the bytecode being executed with source code when the bytecode comes from a class loader of unknown nature, since there is no well-defined mechanism for that. Please note that I am totally fine with stepping through decompiled code. (Even stepping through bytecode instructions would be fine, but AFAIK IntelliJ does not support that). I'm not sure how to provide matching source code myself, so I'd rather see the bytecode to be sure I'm not seeing false information.
What I do not understand is why IntelliJ won't show me that bytecode. Unlike source code, the bytecode is avaiable since after all, it is being executed right now.
What should I do to make IntelliJ show the bytecode being executed?
Update: Steps to reproduce
Use IntelliJ to create an IntelliJ plugin project
create a new folder with an empty build.gradle file in it
Run a "guest" instance of IntelliJ in debug mode
Import the empty gradle project
In the "host" IntelliJ, go to RemoteExternalSystemProjectResolverImpl.resolveProjectInfo and set a breakpoint to the inner call to this.myDelegate.resolveProjectInfo
In the "guest" IntelliJ, hit the Gradle re-import button. It should hit the breakpoint.
Step into the function being called. This will show the frame on the stack, but no code -- not even raw or decompiled bytecode.
You are possibly debugging a library that had been compiled without debug infos. For this purpose, the Java compiler has the command-line option "-g".
I assume you do not understand what bytecode is. This is a bunch of numeric values which cannot be displayed in a similar manner as source code. You would not be able to read bytecode.
What you are usually seeing is decompiled byte code, which depends on the existence of debug infos.

Intellij IDEA Remote Debug invalid breakpoints

Hello, everybody!
I am trying to debug my java8 application running on tomcat 7 with Intellij IDEA Remote Debug.
The problem is when i run debug in idea all off my breakpoints are set to invalid with message:
Line numbers info is not available in class pathToClass
Here is my JAVA_OPTS settings from catalina.bat:
set "JAVA_OPTS=%JAVA_OPTS% -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9999 %JSSE_OPTS%"
Here is my remote debug settins from IDEA
At one point in your build process your Java code is compiled in to classes with the javac compiler (or something equivalent). There is an option to the compiler to include debug information (including line numbers) which you apparently do not have enabled at the moment.
For plain javac add -g.
For ant add debug="true" to the javac task.
For Maven, the default configuration for the maven-compiler-plugin adds debug information, so the explicit setting not to has to be undone.
At one point in your build process your Java code is compiled in to
classes with the javac compiler (or something equivalent). There is an
option to the compiler to include debug information (including line
numbers) which you apparently do not have enabled at the moment. How
do you compile your code? – Thorbjørn Ravn Andersen
Adding debug="true" option to javac solving this problem.
Thanks everybody who helped.
I had the same problem. But the accepted answer did not solve it for me. In my case, the root cause was an interference caused by clover gradle plugin.
To debug the issue, I compared the source code of class A.java with the decompiled code of A.class. The decompiled version had a bunch of junk generated by clover. I just removed the clover plugin from the project, deleted the build folder, invalidated the cache and restarted IDEA. I added the breakpoint and ran it in debug. Voila! It worked this time.
It may not be clover in your case; It could be something else. But, most probably, this breakpoints issue is caused by a mismatch between your source code and compiled class. The best way to verify is to compare the decompiled class with its source.
This can be caused by the minify. Go to your Gradle and set:
Enabled=false
buildShrinkResources=false
Then sync and debug again.
Just had a problem like that, lines were out of sync with a remote server, although the connection was established(I was able to see thread list in IDEA).
The first thing I tried was to put breakpoints not on statements, but on the whole method. Debug hit the breakpoint, but in a weird place(on closing curly brace).
All I had to do, is to remove one empty line from the start of my file, and everything just got aligned with remote.

Why is Visual Studio trying to use the wrong JDK version?

I am trying to build WeatherApp, which comes from this tutorial, but I am seeing this error:
The specified task executable location "C:\Program Files (x86)\Java\jdk1.7.0_55\bin\javac.exe" is invalid.
and this warning (not sure if they are related):
Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="System.Runtime" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" /><bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" /></dependentAssembly></assemblyBinding>
I can doube-click the warning to make it go away, but the error remains. I am not sure why the project is trying to use that version of the jdk, as I have changed my xamarin optioins to point at Program Files instead:
Why is Visual Studio trying to use that versioin of the JDK?
Sometimes there's a sdk.caches file that will hold an old reference. Please try to delete both your obj/bin folders and see if that resolves the issue. If it doesn't, turn up your Build Output verbosity and attach a Build Output Log to your post:
https://forums.xamarin.com/discussion/27515/how-to-obtain-diagnostic-build-logs (XS)
http://blogs.msdn.com/b/msbuild/archive/2005/09/29/475157.aspx (VS)

Eclipse ClassNotFoundException

Everything works fined, but suddenly eclipse stopped execute and junit tests or even main method, when i run them using run as - > Java application, run as -> junit test
It simply throws error
Caused by: java.lang.ClassNotFoundException: package.ClassName
whene ClassName - is class from where i trying to run method main.
It affect only one of my projects ... Different workspaces works fine, other project in same workspace works fine as well.
I'm sure if i recreate current project, error will gone. But the adjustments of this project in eclipse is really hard, so i want to avoid it.
Any clue?
The ClassName is not in the Class Path, if you start from console you should use -cp parameter , if from eclipse, please add ClassName to the sources of current(start) project.
Thanks to adarshr, I was able to look at the Problems window and determine that the build was failing because it could not find a class I had written.
I had used the MS TFS plugin to create a "shelveset" and it was supposed to have removed my pending changes in the process. However, this integration with the TFS snapin and Eclipse is obviously not well implemented, since the Eclipse project still thought the file existed and was complaining that it could not be compiled.
I went and manually deleted those "files" or "non-existing files" from the Eclipse project (that I thought I had removed with the shelveset action) and the problem was solved.
Also....
Another annoying things is that the Tomcat error I was getting by trying to debug within Eclipse was like this:
SEVERE: Error configuring application listener of class
com.CompanyName.ProjectName.servlet.StartupConfigListener
java.lang.ClassNotFoundException:
com.CompanyName.ProjectName.servlet.StartupConfigListener at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643)
In reality, there was no problem at all with StartupConfigListener.java!! The build failed due to the OTHER problems I mentioned above, and therefore I guess this was the first class it attempted to load and failed.... because the entire project hadn't been able to compile perhaps?
(Here's to hoping my next project is using Visual Studio instead of Eclipse!)
Ok, I finally figured it out. The problem was with installed JRE in eclipse setting. I was playing around with this setting and changed installed JRE to JDK, and for some reason it broke the eclipse project.
You can also try going back to the basics. Check your command line and VM args. I've had this situation where a VM arg I was passing in was a path to a file that had a space in the path, and I had forgotten to include the full path in quotes. So e.g., if my arg looked something like
-DFILE=C:\Documents and Settings\myfile
...I'd get a java.lang.NoClassDefFoundError caused by a java.lang.ClassNotFoundException.

Java Reflection not working on my system - working for team members

I am working on a team project in Java. One requirement is that we dynamically populate a drop-down menu of all classes that implement a certain interface. New classes can be added after compile time. To accomplish this we are using reflection.
Problem: All of the drop-down menus are blank on my system. I cannot for the life of me figure out why they are not populating. All other 5 team members have it working on their system.
Things I tired that didn't work:
1) Installing most recent eclipse (galileo) because rest team was using it
2) Re-install most recent java release (jdk1.6.0-17 and jre6)
3) Check PATH and JAVA_HOME variables
Any thoughts as to what else I can try or if something I did should have solved it and didn't? It is driving me crazy.
Edit:
I should have been clearer that we are developing in a team. We are using SVN for version control and we are all running the exact same source code. I even tried checking out a fresh copy of the entire tree from SVN, but I had the same issue with reflection on my system while it worked for teammates.
The team created an executable jar and that ran on everyone's system fine except for mine. Everything worked for me except the reflection bit.
You need to debug your application. This means you have to systematically explore possible causes of the problem. Here are some things that come to mind:
Could your GUI be failing rather than reflection? What if you output with System.out.println() rather than your menu?
Is your reflection code throwing an exception, and are you ignoring it?
Is your reflection code actually being called? Toss a println() in there to be sure!
Is the test for the interface suffering from a typo or similar error that's causing it to fail? Try finding classes that implement Serializable instead!
Is your reflection test running in the main thread and trying to update your GUI? You need to use SwingUtilities.invokeAndWait to get an update to the Swing worker thread.
You're working with Eclipse; Eclipse has a fantastic debugger. Set a breakpoint near where your main action is and then single step through the code.
PATH and JAVA_HOME won't help. PATH only affects dynamically-linked libraries ("native code"). JAVA_HOME is a scripting variable that happens to be used by some Java-based utilities like Ant and Tomcat; it means nothing to the Java runtime itself.
You need to be investigating the classpath, which should be specified by the -classpath option to the java command, in the Build Path in your Eclipse project properties, or in the Class-Path attribute of the main section of a JAR file if you're launching java with the -jar option.
From within your code, you should be able to list the contents of your classpath by examining the system property, "java.class.path"
System.out.println(System.getProperty("java.class.path"));
Problem solution:
Classpath leading to source code must have no spaces in it.
I am running windows XP and, for whatever reason, if the classpath that leads to the jar file or source code that is using reflection has any spaces in it, then the reflection fails.
I took the jar file that works for the rest of my team and ran it from C:\ on my system and the reflection worked perfectly fine.
I do not know why this is so please comment if you know what is happening.
Might be a long shot, but look for differences in security settings for you and your team mates. Article describing more details http://www.ibm.com/developerworks/library/j-dyn0603/ heading "Security and reflection"

Categories