Scala - class is broken - java

I am trying to build a project that has an external dependency on one of the jars. I have a Java version of the class that uses class X from the jar and that builds fine. As soon as I try to build taht using scala, I am getting an error that the "class X is broken" followed by NullPointerExcpetion. What might be the reason for it?

You have a broken dependency on your MANIFEST file. Add the dependency of that X class and try again.

This can happen if your external dependency itself depending on something external. This way builder can not make a whole class, so it is reporting you that class or jar is broken.

Related

Can I force the order of dependencies in my classpath with Gradle?

A project runs on Google App Engine. The project has dependency that uses a class that can't be invoked on App Engine due to security constraints (it's not on the whitelist). My (very hacky) solution was to just copy a modified version of that class into my project (matching the original Class's name and package) that doesn't need the restricted class. This works on both dev and live, I assume because my source appears in the classpath before my external dependencies.
To make it a bit cleaner, I decided to put my modified version of that class into it's own project that can be packaged up in a jar and published for anyone else to use should they face this problem.
Here's my build.gradle:
// my jar that has 'fixed' version of Class.
compile files('path/to/my-hack-0.0.1.jar')
// dependency that includes class that won't run on appengine
compile 'org.elasticsearch:elasticsearch:1.4.4'
On my local dev server, this works fine, the code finds my hacked version of the class first at runtime. On live, for some unknown reason, the version in the elasticsearch dependency is loaded first.
I know having two versions of the same class in the classpath isn't ideal but I was hoping I could reliably force my version to be at the start of the classpath. Any ideas? Alternatively, is there a better way to solve this problem?
Not really sure if this is what people visiting this question were looking for, but this was what my problem and a solution that I reached at.
Jar A: contains class XYZ
Jar B: also contains class XYZ
My Project needs Jar B on the classpath before Jar A to be able to get compiled.
Problem is Gradle sorts the dependencies based on alphabetical order post resolving them which meant Jar B will be coming after Jar A in the generated classpath leading to error while compiling.
Solution:
Declare a custom configuration and patch the compileClasspath. This is how the relevant portion of build.gradle might look like.
configurations {
priority
sourceSets.main.compileClasspath = configurations.priority + sourceSets.main.compileClasspath
}
dependencies {
priority 'org.blah:JarB:2.3'
compile 'org.blah:JarA:2.4'
...
}
It's the app engine classloader I should have been investigating, not gradle...
App Engine allows you to customise the class loader JAR ordering with a little bit of xml in your appengine-web.xml. In my case:
<class-loader-config>
<priority-specifier filename="my-hack-0.0.1.jar"/>
</class-loader-config>
This places my-hack-0.0.1.jar as the first JAR file to be searched for classes, barring those in the directory war/WEB-INF/classes/.
...Thanks to a nudge in the right direction from #Danilo Tommasina :)
UPDATE 2020:
I just hit the same problem again and came across my own question... This time, live appengine was loading a different version of org.json than was being loaded in dev. Very frustrating and no amount of fiddling the build script would fix it. For future searchers, if you're getting this:
java.lang.NoSuchMethodError: org.json.JSONObject.keySet()Ljava/util/Set;
It's because it's loading an old org.json dependency from god-knows-where. I fixed it by adding this to my appengine-web.xml:
<class-loader-config>
<priority-specifier filename="json-20180130.jar"/>
</class-loader-config>
You'll also need a matching dependency in build.gradle if you don't already have one:
compile 'org.json:json:20180130'
According to gradle dependencies documentation, the order of dependencies defines the order in the classpath. So, we can simply put the libraries in the correct order in "dependencies".
But beware! here are two rules with higher priorities:
For a dynamic version, a 'higher' static version is preferred over a 'lower' version.
Modules declared by a module descriptor file (Ivy or POM file) are preferred over modules that have an artifact file only.

NoSuchMethodError after cleaning the project

I'm currently getting this error:
java.lang.NoSuchMethodError: org.json.JSONObject.keySet()Ljava/util/Set;
at ee.ut.cs.Parser.accessLint(Parser.java:39)
I have tried cleaning the project to no awail.
I suspect I have an error in the src/plugin/parse-htmlraw/build.xml while creating the jar file but I'm not certain. I understand that this error is because the function does not exist at runtime, but the object is created which means that the class is there, just not that function. I decompiled the .class file in created jar and it has the necessary functions.
Code is available at https://github.com/jaansusi/WCAGgrader
Q: What is wrong with the build that produces this error?
The problem is that even if I put the necessary class files in the jar I create, they are not linked correctly and the class that's called in the jar can't locate functions inside the other classes. The class object JSONObject is created but the functions inside the JSONObject class can't be found.
If you do not find the problematic version, there is a possibility you get it (especially if you are using Spring) from the following dependency -
<artifactId>android-json</artifactId>
<groupId>com.vaadin.external.google</groupId>
excluding it worked for me,
An easy way of analyzing dependencies is the maven-helper plugin in Intellij, see here
Check for the version you have used.
There might be a case where 2 different versions are being used which in turn causes this error.
To their own maven local repository com\Google\code\gson\gson, see if there are two or more version about json, will have to do is to delete the old, and remember to look at any other place in the project is introduced into the old version of the dependence, if any, change the old version of the dependence to the new version is perfectly solved this problem

Hadoop NoSuchMethodError

Does anyone have any idea why something that used to work before all of a sudden started giving this error? please help
java.lang.NoSuchMethodError: org.apache.hadoop.mapred.Counters.findCounter(Ljava/lang/Enum;)Lorg/apache/hadoop/mapreduce/Counter;
at edu.umn.cs.spatialHadoop.operations.Sampler.sampleMapReduceWithRatio(Sampler.java:214)
at edu.umn.cs.spatialHadoop.operations.Sampler.sample(Sampler.java:543)
at edu.umn.cs.spatialHadoop.operations.Repartition.packInRectangles(Repartition.java:494)
at edu.umn.cs.spatialHadoop.operations.Repartition.packInRectangles(Repartition.java:463)
at edu.umn.cs.spatialHadoop.operations.Repartition.repartitionLocal(Repartition.java:590)
This has been working earlier but suddenly started giving this error. I am using hadoop version 1.2.1
Counter class is included in hadoop-mapreduce-client-core.jar. You must have downgraded it somehow.
If you are using a build tool (maven, gradle...), check your dependencies and make sure they haven't changed. In case of doubt, just apply the latest version.
Else, go to your hadoop-mapreduce-client-core.jar and either check if the method is inside or just get a newer version to replace it in your project.
from org/apache/hadoop/mapreduce/Counter I guess that the hadoop-mapreduce-client-core.jar is missing
This is because of latest compiled class and dependent jar available in the application are of different version. For example: Let Class A compiled with dependent jar X in place then later same Class A compiled in different environment withe dependent jar X1 which consist new method called Y in that. now the class will be compiled because new method Y is available in jar X1 when the same Class A is used in the environment with jar X in place then it leads to the NoSuchMethod Exception when trying to load the class in the class memory. Classloader does the verification of the dependent classes before loading the class in the class memory before invoking real exceution.
Everything were available all jar files and all. After an exhausting work thinking of whats wrong, i decided to reload everything afresh (i.e reload the hadoop files). Thanks to you guys for helping :)

Java 6 runtime not overriding class called from within .jar dependency

I have a project with different classes and packages as dependencies. Note that everything writte below occurs in one project.
I have a class that at some point runs the code getDiagramPanel().setRelationsPaintOrder(new Comparator() {.
getDiagramPanel() calls the method from DjtSheet.class, which is located in a dependency .jar-file. This method returns the DjtDiagramPanel object. I also have a DjtDiagramPanel.java file, which should override the one from the package and contains the method setRelationsPaintOrder().
In Java 7, this works fine. It correctly calls the method from the dependency, which returns the object in the format of the class which overrides the panelclass from the dependency package.
In Java 6 however, the panelclass from the dependency package is returned instead of the one from my project.
java.lang.NoSuchMethodError:
com.dlsc.djt.gantt.DjtDiagramPanel.setRelationsPaintOrder(Ljava/util/Comparator;)V
Note that this message occurs at runtime! Compiling the project gives no errors.
How can I solve this?
This problem definitely means that you have a problem in class path. I guess that the problem is that class DjtDiagramPanel is duplicate and you have 2 different veraions: one that has method setRelationsPaintOrder and second that does not have. Apparently you compile code against the "good" version and run against the "bad" one.
When this happens you can probably change the order of class loading by playing with order of dependencies in project properties of eclipse, but it will just fail later (on production). So, you should find what is the root cause of the duplication.
First find these 2 versions of the same class. Then find how the bad version arrived to your classpath. It typically happes because of 3rd party dependencies. If you are using maven you can use dependency plugin to find the root cause and disable it using tag "exclusion".

The hierarchy of the type Classe is inconsistent

I have a class that implements an abstract class. The abstract class is in another package of my project. Added the package where the class is abstract by Configure build path/Project. In class that implements is accusing the following error: The hierarchy of the type class is inconsistent
Have I to add this package somewhere else?
Thank you!
These errors happened because some interface/class in the hierarchy cannot be resolved.
For example: the error is in your class - class X, X inherits Y, and in turn, Y inherits Z. However, the compiler cannot resolve z (in above error), because z is belong to a library that is not included.
Therefore, you have to add package containing z to the classpath/ or project's Java Build Path (if you are using eclipse).
hope it may help.
Go to the Project Explorer.
Right Click on your Project
Build Path
Configure Build Path
Remove JRE System Library
Click on Add Library
Add JRE System Library
Click on Next and then Finish
The errors will be resolved.
This means you have made an incompatible change in a super class but haven't recompiled it.
I suggest you use a build system like Maven or Ant and/or use an IDE to build all your code.
I was facing this issue in one of My RCP application.
Cause: I was not added core plugin org.eclipse.core.runtime in dependancy section of Manifest file.
When I have added this dependency jar issue has been resolved.
Thanks,
Sid
That means class which implemented by you has reference to the interface or class which again references some other classes or interfaces in other libraries and those are not available.
springframework.aop jar is depends on aopalliance.jar add it to your class path it will resolve ur problm hope it works cos i was facing same prob I added dependent jar so it resolved
right click your project ,Properties- java build path- source- include all the cs file source(it may inherit the files) and sync.
this worked for me and correctly.
I also had this problem when tried to use some class from a plugin project in another one.
I had something like myClass extends pp1Class - here i had the error, pp1Class plugin was added as a dependency. pp1Class extends pp2Class - which was a dependency in pp1 (plugin proj1) but not in my plugin. What i did was go to pp1 and where you have defined the dependency to pp2, click properties and check the "Reexport this dependency" (this is in the MANIFEST.MF).
This should solve the problem, it solved mine.
Another reason for this error is, one of your base classes implements an interface which is in an external library, and your .classpath file is kept on a source control system (therefore readonly).
For instance, your ClassB extends ClassA and ClassA implements InterfaceA which is in LibraryA.jar. ClassA is in ProjectA, ClassB is in ProjectB. ProjectA .classpath file is readonly.
Here you have to export the LibraryA.jar from your ProjectA. But I guess due to an Eclipse bug, when a new team mate connects these projects (or occasionally when you prepare another workspace), he gets this type hierarchy error. Only way to solve this problem is to check-out .classpath file in ProjectA, remove and re-add a library (does not have to be LibraryA.jar). This operation somehow resolves the error.
In the Eclipse, OSGi environment, the required package can be added to the MANIFEST.MF-> Dependencies tab -> Imported packages. This will solve the issue. Or the plugin which contains the class can be added to the Required Plugin-ins
I also face this issue in my maven project using with Eclipse oxygen.1a IDE,
The hierarchy of the type MyClassName is inconsistent
Error showing on class name level,
thereafter I took complete svn update from repository and later Maven -> Update Project and later Project Refresh.
The error was gone...
As per my understanding, this were happening due to unmanaged project version.
I actually added all the related jars and interfaces in build path but still I was facing the error so later someone suggested me to add the j2ee.jar in build path and my error just went away.
The hierarchy of the type A is inconsistent
The above error is mainly because of Some jars missing in the classpath
eg: I was trying to implement an interface "MethodBeforeAdvice"
Here MethodBeforeAdvice implements BeforeAdvice and these two interfaces were present in one jar file called "Spring-aop-4.2.5.Release.jar"
But "BeforeAdvice" interface implements an interface "Advice" which was present in some other jar "aop-alliance-1.0.0.jar" which was not present in my class-path

Categories

Resources