Skip to content

SonarQube complains: Either log or rethrow this exception

I am running SonarQube 5 for code quality check after integrating the code with Maven. Sonar is complaining that I should: Either log or rethrow this exception. in following piece of code: What am I missing here? Answer First of all, is this behaviour correct? Seems a bit weird that you are trying to call convertStringtoDate on the exception message

List.of() or Collections.emptyList()

As an special case of List.of(…) or Collections.unmodifiableList() – what is the preferred Java 9 way of pointing to an empty and immutable list? Keep writing or switch to Answer What is the preferred Java 9 way of pointing to an empty and immutable list? The difference is rather subtle so “preferred” depends on what you want to achieve. Some

log4j2 double dollar $$ sign meaning in configuration

I am reading the configuration part of Log4j2. What is the meaning of double $$ sign? e.g. $${sd:type}? Answer It seems that $ is used as an escape character. As stated in Log4J documentation, Log4j configuration file parser uses Apache Commons Lang’s StrSubstitutor, and this documentation for StrSubstitutor says: The other possibility is to use the escape character, by

Understanding safe access of JNI arguments

I’m doing some research regarding how HotSpot performs garbage-collection and/or heap-compaction while JNI code is running. It appears to be common knowledge that objects could be moved at any time in Java. I’m trying to understand, definitively if JNI is subject to effects garbage-collection. There exist a number of JNI functions to explicitly prevent garbage-collection; such as GetPrimitiveArrayCritical. It makes

Better way to wait to receive Async messages in ActiveMQ

I have used ActiveMQ to Send messages and Receive them Asynchronously. There, I’m having a problem with deciding the best way to waiting in the for messages. Sleeping thread in a loop is one option. But it feels doesn’t look good for me. Can anyone suggest a better way for this. Answer There are two ways to process/consume

Xtend force java 7 language level

I am using Xtend in intellij from the Xtend-plugin. My project language level is set to Java 8 and Xtend compiles fine to Java 8 (e.g. using lambda expressions). For specific reasons, I need Xtend to generate Java 7 code, without changing the language level of my remaining project (Java 8). In the Xtend project settings I can set the

Get Values of variables under an Enum

I want to write into a file/print the constants of an enum, as well as the values of their variables. For example, here is what I thought of doing: However, I am not fully sure on how to do such a thing, as I only recently began working with reflection. This is the code that I currently have. Here is

JUnit – How many files for testing a single class?

Let’s say I have a class and we have to write a tests for it. Some of them will execute once, some of them will execute multiple times. I prepared two test classes – for single tests and for tests with @Parametrized annotation. I wanted to run them from a single file so there is another class