eclipse annotation processor not working. Where are errors shown? - java

Although there are other answers that cover this in some way, I want to have it for someone else that has similar problem and does notice the solution.
After setting up my own annotation processor and it properly working via maven, I got annoyed by being forced to rebuild source with maven on each change that needs the processor to do some magic.
Setting up eclipse to use my annotation processor required me to close annotation processor project so m2e-apt can put processor jars into .factorypath .
But then it stopped working for some reason, and I could not find the reason,

The solution to see the problem was to open:
Window->show view->General->Error Log
After seeing exceptions I was able to fix problems and get it working.
This is also the place where you'll see mesages from your processor

The answer above is correct, but I'd like to put here more details about how to work logging in Eclipse + APT.
Eclipse takes into account only messages send through processingEnv.getMessager().printMessage. If you use printMessage without reference to an element the Eclipse will route your log message to the Workspace Log (Window -> Show view -> General -> Error Log). If you use the printMessage with element reference the Eclipse will route your message to the Problems view (Window -> Show view -> General -> Problems).
If there is some exception during APT rounds Eclipse will log it into the Workspace Log (Window -> Show view -> General -> Error Log)
Eclipse will ignore any other logging methods (e.g. log4j, slf4j, etc).

Related

Source code does not match the bytecode message whiile debugging [duplicate]

I have an app which I am compiling against API level 21:
and then debug it on a real device with API level 23:
The problem is when I try debugging through the Android OS's own classes, I get 'Source code does not match the bytecode'. Why is this happening? The test device the app is running on is API level 23, and the source file being debugged is level 23 as well.
I am really confused. Can anyone explain why I am seeing this message and how I can fix it?
There's an open issue for this in Google's IssueTracker.
The potential solutions given in the issue (as of the date of this post) are:
Click Build -> Clean
Disable Instant Run, in Settings -> Build, Execution, Deployment
Here is my solution:
If you got more than one library version, this may help.
set a breakpoint on the lib source code
let the code run to the breakpoint
you will got these tips
click the arrow icon
you will get this
double click to select the correct lib (normally the highest version of the lib is correct)
I have clicked the "disable" button by mistake, you can enable it in the debugger setting
If you do not have the tips in the step 3, maybe you can check whether you have checked the setting options
You should use an Android emulator with the same api level as the compileSdkVersion.
In your case you should use Android emulator with api level 21.
If you use Gradle, it is probably a problem with Gradle caches. (Reference). Alas, even if you run
gradle --refresh-dependencies
, it is not refreshing really all dependencies. Some rubbish remains. (Reference).
So, the most sure (but drastic and long) variant is to clear all inside from the [user]/.gradle/caches. Or to find your problem project there and clear only its caches.
My app is compiled on API LEVEL 29, but debugging on real device on API LEVEL 28.I got the warning source code does not match the bytecode in AndroidStudio.I fixed it thought these steps:
Go to Preferences>Instant Run: uncheck the instant run
Go to Build>Clean Build
Re-RUN the app
Now, the debug runs normal.
These are the steps that worked for me (For both Mac and Windows):
Click on "File"
Click on "Invalidate Caches / Restart ..."
Choose: "Invalidate and Restart"
Note: It will take less than a minute for small projects, but since my project was big (approximately one million lines of code), it took 20 minutes.
I tried all the solution given here and none of them worked for me. In version 2019.1.3 I just clean & rebuild artifact and it worked; first do Build -> Build Artifacts... -> <select your artifact> -> Clean then click Build or Rebuild from same place.
Go to Project Settings > Artifacts. Select the artifact which has the problem. There is an option "Include in project build". This needs to be checked(enabled). For older versions of IntelliJ this option is "Make on build".
Probably this error message can have more than one cause, my case was not like the one from the OP, in my case this was due to a 3rd party library that required additional libraries.
For example: you manually add X.jar to your LIB, but this X.jar requires Z.jar to work.
It took me sometime to figure out, the message was not helping at all. I had to debug the app until I reached the crashing class, and in that class make sure that all imports were satisfied.
(Particualry: I added MercadoLibre-0.3.4.jar, which required commons-httpclient.jar)
Hope this helps!
This can also happen in case you have enabled ProGuard. In buildTypes set minifyEnabled false, shrinkResources false, useProguard false
I tried the solutions given here while working on an application that used Bluetooth Low Energy(BLE). I tried,
Clean Build
Disabled Instant Run
Invalidate Caches / Restart
all of these failed.
What I did was debug the points where I thought I was getting the warning, I still got the warning but the application was working fine. You can disregard the warning.
You can created AVD, select API Level equal your tagetApi andr compileApi, it works for me.
So I created an account just so I could help fix this problem that is plaguing a lot of people and where the fixes above aren't working.
If you get this error and nothing here helps. Try clicking the "Resume program play button" until the program finishes past the error. Then click in the console tab next to debug and read the red text.
I was getting that source code error even though my issue was trying to insert a value into a null Array.
Step 1 Click the resume button
Step 2 Click the console tab and read the red text
here is cause of why I got this error "source code does not match bytecode". My cause doesn't have anything to do with any API, compiler version..... It is caused by when inflate a layout view into a root view while I mistakenly initiate the inflator in else where (a chuck of "result handler" code that put on top of onCreate function of android app code). Somehow the debugger doesn't give me right hint of this (ex, inflator is not initialized or has instance) when breakpoint is set and stop here.
This happened to me when accidentally I have added the same library multiple times.
implementation 'androidx.appcompat:appcompat:1.1.0'
The above library was added multiple times.
If clean, rebuild, invalidate cache and restart etc. techniques are not working, then try deleting the previous APK and reinstalling the new APK.
Android Studio takes source version equal to Target Version in your application. Compilation performed with source version equal to above mentioned Compile Version. So, take care that in your project Compile Version == Target Version (adjust module's build.gradle file).
I had the same issue and found a solution. If you have a line flagged in red, it will give you this error, but if you un-flag all of the lines it will work normally.
by flagged I mean when you click on the left side where the line numbers are and it highlights the line.
If that is not clear here are pictures.
go from:
flagged line
to:
not flagged line

How to configure Java Annotation Processor(s) in Eclipse?

I have successfully run annotation processor for CLASS level retention annotations via command prompt compiling using Java 8.
However, when I tried to configure the annotation processor in eclipse and tried to run it with "-proc:only" option, it didn't get effective.
I have included the Jar file containing the custom annotation processor class file into the Project Properties -> Annotation Processing -> Factory Path. I have also provided the -proc:only option in Project Properties -> Annotation Processing -> Processor Options, still the annotation processor isn't getting called when a class containing my annotation is executed.
Please help me identifying the required setting or mistake or additional step for running the annotation processor via eclipse.
I was finally able to enable my own annotation processor by adding my jar file.
Right click on the project and select Properties.
Open Java Compiler -> Annotation Processing. Check "Enable annotation processing".
Open Java Compiler -> Annotation Processing -> Factory Path. Check "Enable project specific settings". Add your JAR file to the list.
Clean and build the project.
And it finally worked.
It is very much straightforward provided that whatever APT plug in you are trying to use is correctly configured.
Follow the steps mentioned in above post and the reference image to visualize it. Image showing QueryDsl APT configuration for maven project.
While compiling via command prompt or terminal, you can see all the logs in same screen after the compilation command. In eclipse, these logs can be seen at
Window->show view->General->Error Log
If you want the IDE(Eclipse) to point out the warning, error or other diagnostic message exactly at the particular element in the code editor, we have to call the printMessage method of javax.annotation.processing.Messager with 3 arguments as shown below.
messager.printMessage(Kind.ERROR, "Error Message", element);

Eclipse kepler - Disable javascript validation

I just installed the new eclipse kepler (eclipse 4.3). It shows me hundreds of errors and warnings from third party javascript libraries.
I tried to disable the javasscript validation completely by unchecking "Enable JavaScript semantic validation" in "Preferences/JavaScript/Validator", but with no effect - Errors and warnings are still shown.
Is there another option to disable them or is this just a bug?
Can other people confirm this issue or is it just me? :)
Edit 1: Lavie Tobey pointed out, i should set all validations to "ignore" -> did not help
Edit 2:
Jim Garrison pointed out, i should disable the builder for the projects -> Actually I don't have a javascript builder in there. Disabled for testing purposes all of them, but did not help:
You can go Project properties/Javascript/Include Path/source and exclude the third party components.
There are two places you have to look. You have found the first. The second is in each project's Properties dialog, accessed by right-clicking on the project in Package Explorer and selecting "Properties". There, under Builders you may find a "Javascript Validation" entry, which you must disable.
You have to do this for every project that contains a Javascript Validation builder.
Try this: Open the .project in notepad and remove the javascript validator
I've found that in previous versions of Eclipse, the only way to really get these to go away is to enable it and change every case to "Ignore".
You can switch off (and configure) validation in Preferences/Validation or (for each project) Properties/Validation. However, this doesn't seem to force a cleanup of the messages.
Like it was said : be sure to go to PROJECT properties (right click on project, properties), and not Workspace (Eclipse/preference).
I searched like 20 min before hitting myself ;)
I solved this by choosing a PHP profile for my javascript instead.
Maybe you don't get the same functionality but for me this profile is just fine. Crashes, hangings & frustration went away.
I had the same issue for XML Validation. I deactivated the validators globally and in the projects itself, nothing worked for me. There wasn't even the slightest hint that anything changed. I even uninstalled XML Editor and Validation Plugins without any effect.
In the end the problem was solved in copy-pasting the XML files with a validation error, deleting the old files and renaming the copies files to the original ones. Somehow Eclipse did not re-validate the old files, but the new ones were okay.

I can't debug using breakpoints

I'm getting a strange error message in SpringSource Tool Suite (eclipse) when I try to place breakpoints and debug my project, so in this case, when I start Tomcat for debug it shows me the following error message:
"Unable to install breakpoint in bus.GenBUS$$EnhancerByCGLIB$$749137d3 due to missing line number attributes. Modify compiler options to generate line number attributes.
Reason : Absent Line Number Information"
But I have already controlled and everything is fine in Preferences -> Java -> Compiler section (add line number attr... is checked). My project is Spring MVC project... Any suggestions ?
Ignore that. Even if you get that message, the breakpoint is still triggered. This class is temporal, generated by CGLIB. But it still invokes your class, which has the breakpoint.

Eclipse Failing to build classes

Eclipse has red cross for error on the project but there are no more red crosses on any files or anything in the project.
On running "build Project" there are no .class files created.
There does not seem to be any entries in the log file in workspace/.metadata. In fact, I deleted the log file and a new one has not been created.
I have tried Clean and clean all to no effect.
Any suggestions to look for where there might be a problem with this project ?
Thanks.
If you look in the 'problems' view you'll probably find an error message (this is normally displayed at the bottom, but if not go to : window -> show view -> problems.
Generally it's something like a build path error, or a JVM isn't correctly set.
Thanks...I had confused the Error log view with the Problem view and had not checked it. On looking at problem view, I see there is a dependancy problem.

Categories