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. http://logging.apache.org/log4j/2.x/manual/configuration.html 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. AsyncReceiver.java Sender.java Answer There are two ways to process/consume
IntelliJ IDEA 16 add maven dependencies to classpath
I am new to IntelliJ and using 2016.2 version. Previously I was using Eclipse. I am trying to set up a simple maven spring test project, however I can’t figure out what is wrong. Note: I know what the exception means, and I know the solution using Eclipse Note 2: I tried on a clean Idea installation As per my
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
Should i use the same port numbers when sending data through UDP?
When we send data (in this case) to a client/server, does this really matter to use the same port number? My guess is no, because it doesn’t matter which port you are using when sending data to. (The protocol gives it to you randomly internally – this is the idea?) The only thing has to be kept, the port has
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 MyClass.java 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 – MyClassTestSingle.java for single tests and MyClassTestMultiple.java for tests with @Parametrized annotation. I wanted to run them from a single file so there is another class