I got this error while running a junit-test in my application. Which I later found out because of declared field size
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeHi(TimSort.java:899)
at java.util.TimSort.mergeAt(TimSort.java:516)
at java.util.TimSort.mergeCollapse(TimSort.java:441)
...
org.mockito.internal.configuration.injection.PropertyAndSetterInjection.orderedInstanceFieldsFrom(PropertyAndSetterInjection.java:125)
I found that probable solution would be adding this flag.
-Djava.util.Arrays.useLegacyMergeSort=true in VM args. But I wanted to add in pom.xml
I referred to this how to add VM args using pom xml but it refers mostly for -X flags, what would be an appropriate placement in here?
I updated the pom.xml with the surefire plugin and used argLine parameter as suggested here
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-Djava.util.Arrays.useLegacyMergeSort=true</argLine>
</configuration>
</plugin>
Trere are 2 ways to configure [System Properties in surefire plugin] (https://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html)
Option 1: systemPropertyVariables
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<systemPropertyVariables>
<java.util.Arrays.useLegacyMergeSort>true</java.util.Arrays.useLegacyMergeSort>
</systemPropertyVariables>
</configuration>
</plugin>
Option 2: argLine
Some system properties must be set on the command line of the forked VM, and cannot be set after the VM has been started. These properties must be added to the argLine parameter of the Surefire plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-Djava.util.Arrays.useLegacyMergeSort=true</argLine>
</configuration>
</plugin>
Upgrade your dependencies
On the other hand, I really think that the right solution is to upgrade Mockito to 2.1 or later
2.1 was released in October, 2016, and contains the fix to your issue: Make PropertyAndSetterInjection field sorting consistent #176
I'm getting the following error in my POM file:
POM file:
Error:
I tried to transfer my cucumber project to another machine, but the only warning to pop up was Invalid Plugin configuration :Test Error Ignore.
I've researched this issue but cannot find anything related.
I found the answer it was visible all this time:
instead of
<suiteXmlFiles>
<!-- <suiteXmlFile>testng.xml</suiteXmlFile> -->
</suiteXmlFiles>
<testErrorIgnore>false</testErrorIgnore>
<testFailureIgnore>false</testFailureIgnore>
it should have been:
<!-- <suiteXmlFile>testng.xml</suiteXmlFile> -->
<suiteXmlFiles>
<testErrorIgnore>false</testErrorIgnore>
<testFailureIgnore>false</testFailureIgnore>
'</suiteXmlFiles>'
My oversight.
When debugging I get an warning message on exception saying 'variable info not available - compiled without -g' - how do I set to compile with -g in netbeans?
thanks
As far as I know your own code is compiled with debug information. The Java runtime library, however, isn't.
Please double check that the location you see this message, is in your own code and not the runtime library.
In my Nb 7.4 there is a "generate Debuging info" flag on
project propertyes -> Build -> compile ;
but if you, like me, are using maven, you have to check in pom.xml too
let me show an example:
you can ave a production profile and in that profile you can have the maven compiler plugin with debug setting to false
<profile>
<id>production</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
<showWarnings>true</showWarnings>
<debug>false</debug>
<optimize>true</optimize>
</configuration>
</plugin>
</plugins>
</build>
...
see the false setting
if you have a similar setting on your pom.xml local variable on debug are not show.
I'm using some JSR166 classes with Java 1.6, some of which are under java.util.concurrent. I am on OSX, though I expect this to ultimately run on Linux.
If I set this environment variable I can run my project:
export MAVEN_OPTS=-Xbootclasspath/p:/Users/me/.m2/repository/org/codehaus/jsr166-mirror/jsr166/1.7.0/jsr166-1.7.0.jar
I tried following the instructions here and putting the setting in my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<version>3.0</version>
<compilerArguments>
<verbose/>
<bootclasspath>/Users/me/.m2/repository/org/codehaus/jsr166-mirror/jsr166/1.7.0/jsr166-1.7.0.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
Unfortunately this gave an error about not being able to find java.lang. If I add a reference to classes.jar (apparently OSX's version of rt.jar) in the bootclasspath I can fix that error, but that just puts me back where I started:
java.lang.SecurityException: Prohibited package name: java.util.concurrent
How should I set up maven to use this argument correctly?
You should check security manager. Unfortunately, I don't know specific on OSX. By default, the JVMuses security policies defined in the java.security and java.policy files located under the JAVA_HOME/jre/lib/security folder. Check also -Djava.security.manager and –Djava.security.policy option for your JVM.
Shouldn't you use extdir for this, instead of bootclasspath?
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<compilerArgs>
<arg>-verbose</arg>
<arg>-extdir /Users/me/.m2/repository/org/codehaus/jsr166-mirror/jsr166/1.7.0/</arg>
</compilerArgs>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
From http://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html
I have a Sonar profile in Maven. Everything works fine except the code coverage metric. I want to make Sonar ignore some classes only for the code coverage metric. I have the following profile:
<profile>
<id>sonar</id>
<properties>
<sonar.exclusions>**/beans/jaxb/**</sonar.exclusions>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/*Suite*.java</exclude>
<exclude>**/*RemoteTest.java</exclude>
<exclude>**/*SpringTest.java</exclude>
<exclude>**/*CamelTest.java</exclude>
<exclude>**/*FunctionalTest.java</exclude>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*DaoBeanTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Please help. I tried to add something like
<exclude>com/qwerty/dw/publisher/Main.class</exclude>
but it didn't help
UPDATE
I have a correct Cobertura profile. I tried to add it to the Sonar profile, but still I have 53% instead about 95% like in the Cobertura profile
<profile>
<id>sonar</id>
<properties>
<sonar.exclusions>**/beans/jaxb/**</sonar.exclusions>
<sonar.core.codeCoveragePlugin>cobertura</sonar.core.codeCoveragePlugin>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/*Suite*.java</exclude>
<exclude>**/*RemoteTest.java</exclude>
<exclude>**/*SpringTest.java</exclude>
<exclude>**/*CamelTest.java</exclude>
<exclude>**/*FunctionalTest.java</exclude>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*DaoBeanTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.maven.plugin.version}</version>
<configuration>
<instrumentation>
<excludes>
<exclude>com/qwerty/dw/dao/*</exclude>
<exclude>com/qwerty/dw/domain/*</exclude>
<exclude>com/qwerty/dw/beans/**/*</exclude>
<exclude>com/qwerty/dw/daemon/exception/*</exclude>
<exclude>com/qwerty/dw/daemon/Main.class</exclude>
<exclude>com/qwerty/dw/sink/Main.class</exclude>
<exclude>com/qwerty/dw/publisher/Main.class</exclude>
<exclude>com/qwerty/dw/publisher/dao/*</exclude>
<exclude>com/qwerty/dw/publisher/domain/*</exclude>
</excludes>
</instrumentation>
<formats>
<format>html</format>
</formats>
<aggregate>true</aggregate>
<check>
<haltOnFailure>true</haltOnFailure>
<branchRate>60</branchRate>
<lineRate>60</lineRate>
<totalBranchRate>60</totalBranchRate>
<totalLineRate>60</totalLineRate>
</check>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
At the time of this writing (which is with SonarQube 4.5.1), the correct property to set is sonar.coverage.exclusions, e.g.:
<properties>
<sonar.coverage.exclusions>foo/**/*,**/bar/*</sonar.coverage.exclusions>
</properties>
This seems to be a change from just a few versions earlier. Note that this excludes the given classes from coverage calculation only. All other metrics and issues are calculated.
In order to find the property name for your version of SonarQube, you can try going to the General Settings section of your SonarQube instance and look for the Code Coverage item (in SonarQube 4.5.x, that's General Settings → Exclusions → Code Coverage). Below the input field, it gives the property name mentioned above ("Key: sonar.coverage.exclusions").
For me this worked (basically pom.xml level global properties):
<properties>
<sonar.exclusions>**/Name*.java</sonar.exclusions>
</properties>
According to: http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus#NarrowingtheFocus-Patterns
It appears you can either end it with ".java" or possibly "*"
to get the java classes you're interested in.
Accordingly to this document for SonarQube 7.1
sonar.exclusions - Comma-delimited list of file path patterns to be
excluded from analysis
sonar.coverage.exclusions - Comma-delimited
list of file path patterns to be excluded from coverage
calculations
This document gives some examples on how to create path patterns
# Exclude all classes ending by "Bean"
# Matches org/sonar.api/MyBean.java, org/sonar/util/MyOtherBean.java, org/sonar/util/MyDTO.java, etc.
sonar.exclusions=**/*Bean.java,**/*DTO.java
# Exclude all classes in the "src/main/java/org/sonar" directory
# Matches src/main/java/org/sonar/MyClass.java, src/main/java/org/sonar/MyOtherClass.java
# But does not match src/main/java/org/sonar/util/MyClassUtil.java
sonar.exclusions=src/main/java/org/sonar/*
# Exclude all COBOL programs in the "bank" directory and its sub-directories
# Matches bank/ZTR00021.cbl, bank/data/CBR00354.cbl, bank/data/REM012345.cob
sonar.exclusions=bank/**/*
# Exclude all COBOL programs in the "bank" directory and its sub-directories whose extension is .cbl
# Matches bank/ZTR00021.cbl, bank/data/CBR00354.cbl
sonar.exclusions=bank/**/*.cbl
If you are using Maven for your project, Maven command line parameters can be passed like this for example -Dsonar.coverage.exclusions=**/config/*,**/model/*
I was having problem with excluding single class explicitly. Below my observations:
**/*GlobalExceptionhandler.java - not working for some reason, I was expecting such syntax should work
com/some/package/name/GlobalExceptionhandler.java - not working
src/main/java/com/some/package/name/GlobalExceptionhandler.java - good, class excluded explicitly without using wildcards
When using sonar-scanner for swift, use sonar.coverage.exclusions in your sonar-project.properties to exclude any file for only code coverage. If you want to exclude files from analysis as well, you can use sonar.exclusions. This has worked for me in swift
sonar.coverage.exclusions=**/*ViewController.swift,**/*Cell.swift,**/*View.swift
For jacoco: use this properties:
-Dsonar.jacoco.excludes=**/*View.java
I think you 're looking for the solution described in this answer Exclude methods from code coverage with Cobertura
Keep in mind that if you're using Sonar 3.2 you have specify that your coverage tool is cobertura and not jacoco ( default ), which doesn't support this kind of feature yet
Sometimes, Clover is configured to provide code coverage reports for all non-test code. If you wish to override these preferences, you may use configuration elements to exclude and include source files from being instrumented:
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>${clover-version}</version>
<configuration>
<excludes>
<exclude>**/*Dull.java</exclude>
</excludes>
</configuration>
</plugin>
Also, you can include the following Sonar configuration:
<properties>
<sonar.exclusions>
**/domain/*.java,
**/transfer/*.java
</sonar.exclusions>
</properties>
I had to struggle for a little bit but I found a solution, I added
-Dsonar.coverage.exclusions=**/*.*
and the coverage metric was cancelled from the dashboard at all, so I realized that the problem was the path I was passing, not the property. In my case the path to exclude was java/org/acme/exceptions, so I used :
`-Dsonar.coverage.exclusions=**/exceptions/**/*.*`
and it worked, but since I don't have sub-folders it also works with
-Dsonar.coverage.exclusions=**/exceptions/*.*
I am able to achieve the necessary code coverage exclusions by updating jacoco-maven-plugin configuration in pom.xml
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>pre-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacocoArgLine</propertyName>
<destFile>${project.test.result.directory}/jacoco/jacoco.exec</destFile>
</configuration>
</execution>
<execution>
<id>post-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.test.result.directory}/jacoco/jacoco.exec</dataFile>
<outputDirectory>${project.test.result.directory}/jacoco</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<excludes>
<exclude>**/GlobalExceptionHandler*.*</exclude>
<exclude>**/ErrorResponse*.*</exclude>
</excludes>
</configuration>
</plugin>
this configuration excludes the GlobalExceptionHandler.java and ErrorResponse.java in the jacoco coverage.
And the following two lines does the same for sonar coverage .
<sonar.exclusions> **/*GlobalExceptionHandler*.*, **/*ErrorResponse*.</sonar.exclusions>
<sonar.coverage.exclusions> **/*GlobalExceptionHandler*.*, **/*ErrorResponse*.* </sonar.coverage.exclusions>
If you are looking for exclusion and using Gradle.
Add below lines in build.gradle file:
sonarqube {
properties {
property "sonar.exclusions", "'**/example/your/service/impl/**',"
} }
Note the inner single quote. Good luck.