I'm trying to setup my IntelliJ workspace to do development on an eclipse project. One of the things I've run into is rather confusing:
Error:(24, 8) java: SomeClass.java:24: getHeader(java.lang.String) in org.springframework.mock.web.MockHttpServletResponse cannot implement getHeader(java.lang.String) in javax.servlet.http.HttpServletResponse; attempting to use incompatible return type
found : java.lang.Object
required: java.lang.String
The problem is the following class definition:
public class SomeClass extends MockHttpServletResponse {
The problem seems to be because MockHttpServletResponse implements Collection<String> getHeaders(String) as public List getHeaders(String name). Here, I can see that the implementing method uses a raw List where the parent asks for a generic Collection typed with String. Aside from being potentially not type-safe, why would IntelliJ mark this as a complier error instead of a warning?
I have no option of changing any of these libraries. I'm simply trying to make work in IntellJ 14 what already works without complaints in Eclipse 4.3+.
EDIT:
I have since updated to IntelliJ 15.0, and the project is using Java 1.7 now instead of 1.6. I am still running into this issue with IntelliJ, but the issue is not presenting itself at all in Eclipse. I can compile the project using existing Ant scripts via IntelliJ, but I cannot debug through the IDE.
Here is my class definition
public class ExecutableServletResponse extends MockHttpServletResponse {
...
Here is the error showing in my 'Messages' pane:
Error:(24, 8) java: getHeader(java.lang.String) in org.springframework.mock.web.MockHttpServletResponse cannot implement getHeader(java.lang.String) in javax.servlet.http.HttpServletResponse
return type java.lang.Object is not compatible with java.lang.String
The project SDK is using version 1.7 (1.7.0_79 to be exact). Language level is 7. Module SDK and Language Levels match the project.
I've tried using the eclipse compiler, but the app still doesn't fully compile, and will fail to run presumably because it fails to compile this class, and a whole part of the webapp doesn't compile as a result.
Here's a screenshot of my error, FWIW:
You are seeing the error in your class, but the real issue is that the Spring mock library is not compatible with the Servlet Specification you are using. This may happen if you upgraded to the Servlet 3.0 Spec (or added a dependency that pulled it in transitively). Check your dependencies and ensure that either:
Only Servlet 2.5 is provided, or
You are using a version of Spring that is compatible with Servlet 3.0. Also ensure that all of your Spring dependencies are using the same version.
This combination should work:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
</dependency>
as should this:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.1.0.RELEASE</version>
<scope>test</scope>
</dependency>
But this will fail:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.2.RELEASE</version>
<scope>test</scope>
</dependency>
The fact that it works in Eclipse but not in IntelliJ suggests that you have multiple dependencies that provide the same classes. There is no guarantee as to which jar the system will use to load the class. This may either be because you have both servlet-api and javaee-web-api on your classpath or because you have both spring-mock and spring-test on your classpath. After version 2.0.8, the classes in spring-mock were moved to spring-test and only version 3.1.0.RELEASE and higher of spring-test are compatible with Servlet 3.0.
After developing Spring roo project, I found following errors in class:
The import javax.validation.constraints.NotNull cannot be resolved
NotNull cannot be resolved to a type
I am using STS 3.1.0.RELEASE
How can this be rectified?
I had the same problem. I found out that the recent versions of Spring Boot needs the separate dependency for Validation. I Tried adding below dependency in pom.xml file and it worked.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
The jar containing this class must be added to the build path of your project: http://mvnrepository.com/artifact/javax.validation/validation-api/1.0.0.GA
for JDK-9 the old version of "javax.validation" is not supporting. So we should add latest version.
we will know the latest version of any jar the following way
C:\Users\username\.m2\repository\javax\validation\validation-api
The above folder should have all versions of the jar, then you can add the latest version as dependency in the pom.xml file the following way
In my case "2.0.0.final" is the latest version.
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.0.Final</version>
</dependency>
from Spring boot 2.3 version you have to add this dependency in your pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
the web starters no longer contains the validation so you have to add it manually
Im using JDK JAVA 8 and i still had a similar problem. The error disappeared just by adding the following Sample in my pom.xml
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
The following artical helped me find the solution:
"https://www.baeldung.com/javax-validation"
If you are using SpringBoot and you are migrating to Spring Boot 3, you need to replace all your references of javax.validation with jakarta.validation.
Check the release notes of Spring Boot:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Release-Notes
In addition to copying and pasting .jar en <root-project>/lib you also have to add them in Project Structure > Libraries > Classes
GL
Hibernate Validator
Before, Gradle included this dependency by default. I don't know what happen. You have to add manually this dependence: implementation 'jakarta.validation:jakarta.validation-api:2.0.2'
I had the same error and I simply downloaded API from
: https://mvnrepository.com/artifact/javax.validation/validation-api/1.0.0.GA
: https://mvnrepository.com/artifact/javax.validation/com.springsource.javax.validation/1.0.0.GA
It started to work -))))))))
Intellij solution:
After pasting the code below you need to close intellij (entirely) then open again.
pasted the following:
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>2.0.2</version>
</dependency>
there are also following versions there.
If you are using gradle, in "build.gradle" file add the following in the "dependencies"
implementation 'org.springframework.boot:spring-boot-starter-validation'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
I have a Java Maven project that I developed a while ago and that doesn't work anymore. It uses a parent pom together with another Maven project in which I think the Jena version was changed and it also uses an external library that uses Jena. The Maven dependency is:
<dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>jena</artifactId>
<version>2.6.4</version>
</dependency>
When I execute my tests I get the following errors:
java.lang.NoClassDefFoundError: Could not initialize class
com.hp.hpl.jena.query.ARQ
java.lang.NoClassDefFoundError: org/apache/jena/iri/IRIFactory
at org.openjena.riot.system.PrefixMap.add(PrefixMap.java:54)
at com.hp.hpl.jena.sparql.util.MappingRegistry.addPrefixMapping(MappingRegistry.java:33)
at com.hp.hpl.jena.query.ARQ.init(ARQ.java:449) [...]
The errors are not thrown by my code directly but by the library I include. Can I prevent this by downgrading the Jena version in the parent pom or what can I do here?
P.S.: I now have a minimal code example that reproduces the error (java.lang.NoClassDefFoundError: org/apache/jena/iri/IRIFactory):
import org.junit.Test;
import com.hp.hpl.jena.query.ARQ;
public class DependencyTest
{
#Test
public void testARQ()
{
ARQ a = new ARQ();
}
}
And I guess it comes from this dependency:
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>2.9.1-incubating-SNAPSHOT</version>
</dependency>
I know there is probably a factory instead of a constructor but I guess this still shows where the problem is.
P.S.: I noticed that I had the dependencies "jena", "arq" and "jena-arq":
<dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>arq</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>2.9.1-incubating-SNAPSHOT</version>
</dependency>
dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>jena</artifactId>
<version>2.6.4</version>
</dependency>
So I thought maybe I have too much overlapping dependencies and commented out "jena" and "arq". But I still get the error
java.lang.NoClassDefFoundError: Could not initialize class com.hp.hpl.jena.query.ARQ
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.<init> [...]
I also tried out forcing a non-snapshot-version 2.9.0-incubating, but then I still get the NoClassDefFoundError with and without using the "jena" and "arq"-dependencies.
P.P.S.:
I still get the same error even when I use the following dependencies:
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>2.9.0-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>2.7.0-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-iri</artifactId>
<version>2.7.0-incubating</version>
</dependency>
You can search for the missing class using the Maven Central search application
http://search.maven.org/#search|ga|1|fc%3A%22com.hp.hpl.jena.query.ARQ%22
It demonstrates that the dependency you appear to be missing is:
<dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>arq</artifactId>
<version>2.6.0</version>
</dependency>
Doesn't appear to be a version 2.6.4, but you're probabily best advised to go for a more modern version (This project was recently donated to apache)
Instructions for using Apache Jena with Maven are here:
incubator.apache.org/jena/download/maven.html
Specifying ARQ 2.9.0 as a dependency in your project pom.xml will pull in the other Jena components that you need.
I finally resolved this error by excluding the "jena"-Dependency brought in as a transitive dependency from some library.
I have downloaded some open source software written in Java and tried to compile it using Eclipse.
I got the error: "The hierarchy of the type 'Class name' is inconsistent" in some files.
What causes these errors and how do I fix them?
It means you are trying to implement a non-existing interface or you're extending an non-existing class.
Try to refresh your Eclipse.
If it doesn't work, it may mean that you have a reference to a JAR that is not in the build path.
Check your project's classpath and verify that the jar containing the interface or the class is in it.
Sometimes it happens when you add a jar that YOU need, but don't include the jars that IT needs. In my case adding all the jars in tomcat/lib helped me to solve this problem. I am working on a web-app.
Check your errors (tab "markers"). I had also the following error:
Archive for required library in project cannot be read...
and when that was fixed the "inconsistent-error" disappeared.
Actually I had added jars to the build path, but for some reason they could not be read with error
Archive for required library in project cannot be read or is not a valid ZIP file
So instead I added them as "External Jars". That helped and all compilation problems were no more!
I had this problem after I upgraded the JDK to a new version. I had to update the references to libraries in Project Properties/Java Build Path.
One more case I have had. Give the correct project path, and import it to eclipse.
Then go to Project--> Clean --> Clean all projects.
You should clean the project , or restart Eclipse.
You will see this error in case a some class in your library file you have in classpath has reference to non-existing classe(s) which could be in another jar file. Here, I received this error when I did not add org.springframework.beans-3.1.2.RELEASE.jar and had extended a class from org.springframework.jdbc.core.support.JdbcDaoSupport, which was in org.springframework.jdbc-3.1.2.RELEASE.jar of my classpath.
The problem may be that you have included incorrect jars. I had the same problem and the reason was that I had included incorrect default JRE library in the build path of the project. I had installed Java with another version and was including JRE files of Java with a different version. (I had installed JRE 1.6 in my system and was having JRE library 1.7 included in the build path due to previously installed Java) May be you can check if the JRE library that you have included in the build path is of correct version ie. of Java version that you have installed in your system.
I 've experienced this problem on Eclipse Juno, the root cause was that although some spring jars were being included by transient maven dependencies they were included in incorrect versions.
So you should check if using a modularized framework as spring that every module (or at least the most important: core, beans, context, aop, tx, etc.) are in the same version.
To solve the problem I 've used maven dependnecy exclusions to avoid incorrect version of transient dependencies.
Error : the hierarchy of the type "class name" is inconsistent error.
solution :
class OtherDepJar {} --> is inside "other.dep.jar" .
class DepJar extends OtherDepJar {} --> is inside "dep.jar".
class ProblematicClass extends DepJar {} --> is inside current project .
If dep.jar is in the project's classpath, but other.dep.jar isn't in the project's classpath, Eclipse will show the" The hierarchy of the type ... is inconsistent error"
To me, the issue was due to wrong imports. In fact, one need to update the imports after adding the v7 support library.
It can be fixed by doing as follows, for each class of your project:
Delete all the lines with import android.[*], in each class
Reorganize your imports: from the context menu select Source/Organize Imports or (CTRL+SHIFT+O)
When prompted, select the libraries android.support.[*] (and not android.[*]).
It was definitely because missing dependencies that were not in my maven pom.xml.
For example, I wanted to create integration tests for my implementation of the broadleaf ecommerce demo site.
I had included a broadleaf jar with integration tests from broadleaf commerce in order to reuse their configuration files and base testing classes. That project had other testing dependencies that I had not included and I received the "inconsistent hierarchy" error.
After copying the "test dependencies" from broadleaf/pom.xml and the associated properties variables that provided the versions for each dependency in broadleaf/pom.xml, the error went away.
The properties were:
<geb.version>0.9.3</geb.version>
<spock.version>0.7-groovy-2.0</spock.version>
<selenium.version>2.42.2</selenium.version>
<groovy.version>2.1.8</groovy.version>
The dependencies were:
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>integration</artifactId>
<type>jar</type>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.broadleafcommerce</groupId>
<artifactId>broadleaf-framework</artifactId>
<version>${blc.version}</version><!--$NO-MVN-MAN-VER$ -->
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>com.icegreen</groupId>
<artifactId>greenmail</artifactId>
<version>1.3</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>2.5.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymockclassextension</artifactId>
<version>2.4</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.9</version>
<type>jar</type>
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gebish</groupId>
<artifactId>geb-core</artifactId>
<version>${geb.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gebish</groupId>
<artifactId>geb-spock</artifactId>
<version>${geb.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>${spock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${selenium.version}</version>
<scope>test</scope>
</dependency>
<!-- Logging -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.6.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
If the extended class has the issue then the above error message will gets displayed.
Example
class Example extends Example1 {
}
fix the issues in Example1
I had the same exact problem marker and solved it by removing the #Override annotation from a method that was in fact the first implementation (the "super" one being an abstract method) and not an override.
In my case, the import references in many of the classes contained an extra word. I solved it by editing all the files to have the correct imports. I started doing the edits manually. But when I saw the pattern, I automated it with a find..replace in eclipse. This resolved the error.
For me it was changing the Android API level to one with Google APIs
I was having this problem too... I found out that the hierarchy of the class that was throwing this exception, cannot be traced all way back to its root class by eclipse... I Explain:
In my case, I have 3 java project: A, B and C... where A and B are maven projects and C a regular java eclipse project...
In the project A, i have the interface "interfaceA" ...
In the project B, i have the interface "interfaceB" that extends "interfaceA"
In the project C, i have the concrete class "classC" that implements "interfaceB"
The "project C" was including the "project B" in its build path but not "project A" (so that was the cause of the error).... After including "project A" inside the build path of "C", everything went back to normal...
I had a class that extends LabelProvider in a project with OSGi, there the error occured. The solution was: Adding org.eclipse.jface to the required plugins in the manifest.mf instead of importing the single packages like org.eclipse.jface.viewers
if you are importing the eclipse project just
1. Go to the java build path setting under the project properties.
2. In case the JRE System library has an error sign attach to it double click it to open the Edit library window
3. Change the execution environment to the correct java version of the system or choose edit the other settings by checking the radio buttons assign to them.
4. Click finish
When importing a GWT project in Eclipse without installing "Google Plugin for Eclipse", this will occur. After installing "Google Plugin for Eclipse", this error will disappear.
Right click on the project folder and select "Java Build Path". Under "Java Build Path" you should be able to see libraries. Eclipse will show errors in any of those libraries. Fixing those issue will help to resolve the issue.
I had this error after doing some git merge from a branch where my classes extended a new interface.
It was enough to Refresh (F5) the File-Tree in the Package Explorer frame of Eclipse.
It seems that Eclipse did not update everything properly and so the classes were extending a non-existing-yet interface. After refresh, all errors disappeared.
I had to switch from Eclipse Oxygen that I got from IBM and used IBM JDK 8 to Eclipse Photon and Oracle JDK 8. I'm working on Java customizations for maximo.
This error will also appear when one of the jars required by the existing dependencies is not available in current project path.
Ex:-> Current Proj depends on Lib1 depends on Lib2.
If we use one of the classes in Lib1 but Lib2 is not packaged in Lib1 or not available in current project path you'll see the issue.
When minimising yui with 2.4.6, I get this problem:
java.lang.StringIndexOutOfBoundsException: String index out of range: 232
at java.lang.String.substring(String.java:1934)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.printSourceString(JavaScriptCompressor.java:267)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(JavaScriptCompressor.java:330)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.<init>(JavaScriptCompressor.java:533)
It works when started through my IDE but when deployed to jboss it doesn't. This place: http://yuilibrary.com/forum/viewtopic.php?p=20086 has some discussion of the same problem.
Apparently the issue is around org/mozilla/javascript/Parser being in the two jars that are pulled in from my maven config:
<dependency>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
<version>2.4.6</version>
</dependency>
Is there any way I can solve this using maven exclusions etc. or by upgrading my version of YUI. It seems daft that it just doesn't work and I don't want to have to write a custom classloader.
Please help!
Workaround: For JBoss AS 7.1.1.Final and YUICompressor 2.4.7
Exclude rhino from dependency:
<dependency>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
<version>${yuicompressor.version}</version>
<exclusions>
<exclusion>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
</exclusion>
</exclusions>
</dependency>
Why? See https://github.com/greenlaw110/greenscript/pull/29#issuecomment-4017147
Note: if you have a rhino in classpath by some other way, so seems like you'll get this error again.
I solved this problem by repackaging yuicompressor myself to include most of the rhino source. See my reply to Howard M. Lewis Ship.
The repackaged source can be found here : http://viscri.co.uk/labs/tapestry/yuicompressor-rhino-bugfix-5.0.jar. Just add this to your pom:
<dependency>
<groupId>yuicompressorbugfix</groupId>
<artifactId>yuicompressor-rhino-bugfix</artifactId>
<version>5.0</version>
</dependency>
If you don't run your own version of nexus, you'll have to install it on the machine that you want to build on. This is the command you need I think: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
You'll also need to exclude the yuicompressor version that tapestry pulls in:
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-yuicompressor</artifactId>
<version>5.3.2</version>
<exclusions>
<exclusion>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
</exclusion>
</exclusions>
This should work.
The selected answer's (as of 9/26/2014) jar doesn't exist anymore.
So, I created a fork of yuicompressor where entire rhino package is embedded into the yuicompressor package and namespaced it under yui.
https://github.com/timothykim/yuicompressor
Just clone the repo and run ant to obtain the jar.
Hope this helps anyone else who stumbles unto this problem.
Really, you're having class loader problems in JBoss?
You're going to have to do some kind of exclusion on the competing rhino JAR file. Why is Rhino on the classpath? It may be an optional feature of JBoss you can turn off and avoid the conflict that way.