Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library source does not match the bytecode for class

No idea what's wrong here.. I removed all files I had from the local maven repository and let it download everything from scratch but I can't get rid of this error:

enter image description here

Why am I seeing this and how can I get rid of it?


[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ wordvectors ---
[INFO] masterthesis.code:wordvectors:jar:1.0-SNAPSHOT
[INFO] +- org.apache.spark:spark-core_2.10:jar:1.6.0:compile
[INFO] |  \- org.apache.hadoop:hadoop-client:jar:2.2.0:compile
[INFO] |     \- org.apache.hadoop:hadoop-common:jar:2.2.0:compile
[INFO] |        \- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] |           \- (commons-collections:commons-collections:jar:3.2.1:compile - omitted for conflict with 20040616)
[INFO] \- org.deeplearning4j:deeplearning4j-ui:jar:0.4-rc3.8:compile
[INFO]    \- org.deeplearning4j:deeplearning4j-nlp:jar:0.4-rc3.8:compile
[INFO]       \- it.unimi.dsi:dsiutils:jar:2.2.2:compile
[INFO]          \- commons-collections:commons-collections:jar:20040616:compile
like image 786
Stefan Falk Avatar asked Apr 20 '16 19:04

Stefan Falk


6 Answers

Had same problem - did a gradlew clean from the command line, then went into Android Studio and did a File -> Invalidate Caches and Restart and all was well again..

like image 66
LanDenLabs Avatar answered Nov 20 '22 14:11

LanDenLabs


There's nothing wrong with IDEA, nor your dependencies or local maven caches, it's correctly identifying the mismatch.

Here's how to check:

  • Open class in question
  • Click "Show diff"
  • Choose "Ignore whitespaces and empty lines"

diff screenshot

You can clearly see (ignoring JavaDoc and FQCNs) that the class file has extra checks included for the @NonNull annotated arguments. The import says lombok.NonNull, and the documentation shows this transformation will happen.

I guess the best course of action is either to ignore this warning or ask the project's maintainers to build the sources.jar from the lombok-processed source code if that's possible. I think they'll need to employ delomboking and this Maven plugin, but never built lombok code myself.

like image 35
TWiStErRob Avatar answered Nov 20 '22 14:11

TWiStErRob


In solving this, I had no need to mess around with Maven, and dealt with IntelliJ IDEA alone.

For me this problem arose out of confusion between three concepts in the IntelliJ IDEA: modules, libraries and dependencies. I had different projects, using different packages, some of which were referring to each other in inconsistent ways. I was also being inconsistent about how to refer to downloaded third-party packages.

It was easy once I distinguished the three concepts of modules, libraries and dependencies. How I clarified them in my mind:

1) Libraries refer to code (compiled or not) which is not going to change.

2) Modules refer to parts of the project (yours if you are working alone) where the code is subject to change.

3) A dependency (for this conversation) is a library or other module which a particular module will use.

I got the error from adding the code of an ongoing project, which was originally created by another IDE, as a dependency in the IntelliJ IDEA. In theory this should work, and it does, but like you I can't ignore a big red banner across the top of my development environment!

To solve the problem:

Modules Open File>Project Structure>Modules, and using the top left green plus sign (not the one to the right) added other projects where the code is likely to change. This makes them 'alive' to IntelliJ, and not a dusty old immutable library which, if changed, might cause the alarm banner to shout at you. At this stage, only use the big panel taking up most of the dialog for checking the imported jars, source code, etc., to verify what you want has arrived.

Adding a module

Libraries Open File>Project Structure>Libraries, and again using the top left green plus sign add the folder containing the code that will not change. The other green plus sign to the right allows you to add internal folders to an already added library, but IntelliJ is good at finding these in different project structures, so consider starting from scratch adding a new library, rather than adding specific folders that you think are missing and causing multiple copies to exist, another thing which causes confusion (understandably) to IntelliJ.

Adding a library

Dependencies Now everything should be ready for you to return to File>Project Structure>Modules. This time go to the large panel taking up most of the dialog and change to the 'Dependencies' tab. My preferred way of working at this stage (particularly when the project is large and complex) is to work my way down the listed modules, adding the libraries and module dependencies for each module as I go. This time for each module use the green plus sign to the right to add each library or module that you need, and these should be offered to you from the ones added in the last step.

enter image description here

WARNING There are two important steps which you should be careful of when finishing the process:

1. Make sure that each dependency you added for each module has scope 'Compile' in the dependencies tab.

2. When you are finished, click the Apply button at the bottom of the Project Structures dialog before clicking OK. It seems like it should be automatic, like so much else in IntelliJ, but I do not think it is. I have lost changes I have made to the Project Structure by not clicking Apply before exiting the dialog.

like image 19
Ger Avatar answered Nov 20 '22 13:11

Ger


I had this problem and to my knowledge, I know two solutions to solve this:

  1. click "build" on top of your IntellIj windows, then "Build project"

and/or

  1. on the right side, you click on "maeven projects"(vertically written in small), then "clean"
like image 1
Charles Julien Avatar answered Nov 20 '22 12:11

Charles Julien


Just now I had this problem,

What helped me:

I've found .ideaLibSources folder, by selecting 'Copy path' in context menu after right-clicking on jar file (You could find jar-file link in upper region of idea, when file is opened in editor and it is in focus) then just removed unwonted-sources.jar from this folder. aaand redownload.

btw invalidate/restart didn't help

like image 1
Sergey Dvoreckih Avatar answered Nov 20 '22 13:11

Sergey Dvoreckih


Check for multiple sources attached to lib

It could be due to multiple sources defined in Libraries. Check and remove multiple sources under File > Project Structure > Libraries > lib with issue > Sources

e.g. File > Project Structure > Libraries > Maven: com.rohit:example:1.0.0 > Sources --> remove multiple sources

like image 1
Rohit Tandon Avatar answered Nov 20 '22 14:11

Rohit Tandon