Sunday, April 21, 2019

SImple Spring Boot and React working example

Matt Raible is a boss and he is so straight to the point and precise.

Remember that if you have in your pom.xml the dependency spring-boot-starter-security, then Spring Boot will enable security by default with username "user" and a dynamically generated password:

so for the time being I have excluded this dependency.

This should explain more how to handle web security with the great fluent api provided by Spring.

Friday, April 19, 2019

Intellij and WebLogic

Wednesday, April 17, 2019

never copy/paste from outlook or Word

Microsoft sucks

The command on the left was copied from an email (Outlook). And it was failing, returning EVERYTHING, not only config.xml.

Then I have typed all over again (right pane) and it was working

Visually they look absolutely the same, even in Notepad++. But a closer inspection reveals hidden chars.

Copying and pasting from Outlook or Word has caused more victims than the 1919 Spanish Flu.

I remember a production delivery failed because someone copied a command from a Word document where Word had capitalized a property name.


package com.example.demo;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class DemoApplication implements CommandLineRunner {

    public static void main(String[] args) {, args);

    public void run(String... args) throws Exception {
        CompletableFuture<String> completableFuture = new CompletableFuture<String>();
        completableFuture.complete("Future's Result");

        String result = completableFuture.get();

        CompletableFuture<Void> future = CompletableFuture.runAsync(new Runnable() {
            public void run() {
                // Simulate a long-running Job
                try {
                } catch (InterruptedException e) {
                    throw new IllegalStateException(e);
                System.out.println("I'll run in a separate thread than the main thread.");
        // Block and wait for the future to complete


Ruminations about Jenkins

The jobs are defined in here:


For every project (item), there is a folder.

In every folder there is a config.xml file which hopefully should contain the entire project definition.

My assumption is that one should simply save the config.xml, and this is enough to recreate the project elsewhere.

I am worried because the Project definitions in Jenkins are not saved in bitbucket,
and we don’t have an automated way to export them from PROD and import them to a UAT instance.

One COULD tar the $JENKINS_HOME/jobs folder, but it’s very bulky.

[jobs]$ cd myproject/

[myproject]$ ls -ltra

drwxr-xr-x. 3 pippo pippogroup 4096 Jul 18 2016 modules
-rw-r--r--. 1 pippo pippogroup 6 Apr 25 2018 nextBuildNumber
lrwxrwxrwx. 1 pippo pippogroup 26 Apr 25 2018 lastSuccessful -> builds/lastSuccessfulBuild
lrwxrwxrwx. 1 pippo pippogroup 22 Apr 25 2018 lastStable -> builds/lastStableBuild
drwxr-xr-x. 5 pippo pippogroup 4096 Apr 25 2018 workspace
drwxr-xr-x. 24 pippo pippogroup 4096 Apr 25 2018 builds
-rw-r--r--. 1 pippo pippogroup 7257 Apr 25 2018 config.xml
drwxr-xr-x. 5 pippo pippogroup 4096 Apr 25 2018 .
drwxr-xr-x. 360 pippo pippogroup 20480 Mar 18 15:06 ..

especially the workspace is a PIG

So for the time being I will simply tar up all the config.xml and untar them in UAT:


find . –maxdepth 2 –name config.xml | tar cvf /var/tmp/alljenkinsconfig.tar –T –

(maxdepth is important to avoid picking up files coming from the workspaces)

However we should really really IMHO push all those config.xml to bitbucket, regularly – ideally automatically whenever someone changes a config.xml:

git init
#set origin and remote
find . –maxdepth 2 –name config.xml –exec git add {} \;
git commit -m "blablabla"
git push

Incidentally, many project folders contain spaces, which makes it much trickier to write scripts to manipulate them.

I am not in favor of Capital Punishment, apart from cases when people create folders containing spaces.

Jenkins sucks anyway. Design is from Napoleonian Era, UI made by a freak, configuration freakishly XML based without fluent Administration Groovy API,
actually in the old times they were much better at designing stuff, think of the Tour Eiffel or the Pyramids and the Coliseum.
Nowadays any idiotic monkey can code freakish products like Maven or Jenkins and become a celebrity.

Thread dumps analysis

this post provides useful insights on how to detect issues from a Thread Dump:

For a quick thread dump consolidation one can use or (both are quite equivalent)....

Problem is that these tools are Application Server agnostic and don't tell you what is normal and what is not. I think some AI should be added to the tool, plus some graphical rendering for instance of the lock analysis.

When I have time I want to look into

Anyway advanced thread analysis is a skill in itself and should be done with proper tooling... manually sorting stuff can be overwhelming for the regular human being.

Saturday, April 13, 2019

Mockito revisited

I have used Mockito in 2010. Then I never did SERIOUS Java development any more (shame on me...)

Yet I strongly believe that a solid implementation of Mocks is the foundation of healthy, fully testable software.
If you can't entirely automate your application tests, you are playing with your life.


source code is here

List mockedList;

List spiedList = new ArrayList();

ArgumentCaptor argCaptor;

I am getting : Illegal reflective access by org.mockito.internal.util.reflection.AccessibilityChanger
Hopefully Mockito folks will fix this one da.

Wednesday, April 10, 2019

Gradle plugin for Jenkins

Maven Sucks, so we welcome Gradle - it can't possibly be worse than Maven!

it seems that Gradle Plugin is installed as part of the "common plugins". I use an old Jenkins 2.138.

export GRADLE_HOME=/home/centos/gradle/gradle-4.8
#make sure $GRADLE_HOME/bin is in $PATH
cd /home/centos/gitclones
git clone
cd gradle-simple/
gradle clean
gradle build
#check if jar was built
ls -ltra build/libs

I configure a freestyle Jenkins item to checkout from Github and "clean build" as gradle tasks...
Then I inspect /home/centos/.jenkins/workspace/gradletest/build/libs/ and the jar has been built there... great!

If I want to copy the plugin to another machine, it's in /home/centos/.jenkins/plugins/gradle.jpi


Manifest-Version: 1.0
Plugin-Dependencies: structs:1.3
Long-Name: Gradle Plugin
Compatible-Since-Version: 1.0
Plugin-Developers: Stefan Wolf:wolfs:
Group-Id: org.jenkins-ci.plugins
Extension-Name: gradle
Plugin-Version: 1.31
Jenkins-Version: 1.651.3
Short-Name: gradle

Tuesday, April 9, 2019

Effective Java third edition

the source code:

*clone (p. 86)
copy constructor/ copy factory
java.util.Comparator.comparingInt + thenComparingInt

immutable objects

composition over inheritance

default methods

generics and collections

unbounded wildcard types (<?>)

PECS producer extends consumer super



Monday, April 8, 2019

Generics and collections

this one has no compilation errors:

Set a;
Set<Object> b;
Set<? super Object> c;

a = new HashSet();
b = new HashSet<>();
c = new HashSet<>();

c = a;
c = b;
b = a;
b = c;
a = c;
a = b;

but if I use

Set<Object> b;
Set<?> c;

then "c = b" gives compilation error

Error:(26, 13) java: incompatible types: java.util.Set cannot be converted to java.util.Set

This is interesting, since ? means "any Object and subclasses"... while "? super Object" means "Object and its superclasses"
but Object has no superclasses, so effectively it's only Object.

If I use:
b = new HashSet<>();
Set<?? extends Object> c;

b = c;
fails with the same error:

Error:(26, 13) java: incompatible types: java.util.Set cannot be converted to java.util.Set

The raw type a can be assigned all the time to all the others.

similarly, collections are INVARIANT:
Set<Number> numset = new HashSet<>();
Set<Integer> intset = new HashSet<>();
Set<?> allset = new HashSet<>();

numset = intset; // INVALID
intset = numset; // INVALID
allset = numset; // VALID
numset = allset; // INVALID

but arrays are COVARIANT:

Number[] numarr = new Number[1];
Integer[] intarr = new Integer[1];
numarr = intarr; // VALID
intarr = numarr; // INVALID

Sunday, April 7, 2019

Amazing brushes by Reto

a colleague of mine, Reto, is a passionate photographer and Photoshop artist , here some links to his creations:

Intellij , maven and the source or target java language level

I create a new Java "maven" project, set it to Java 12 (ctrl-alt-shift-S, MOdules, Language level), but when I build I get:

"Warning:java: source value 1.5 is obsolete and will be removed in a future release"

Apparently this is due to the prehistoric, nonsensical Maven Compiler Plugin using Java 1.5 by default

you can either insert in the pom.xml :




Remember also to make sure that ctrl-alt-S (Settings) Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing is set to use JDK 12. So complicated. So brittle. So Maven.

Working with Maven is like traveling back to prehistoric times, like the Mural de la Prehistoria in Cuba,

developers on the right about to be eaten by Maven on the left

Priceless String manipulation Intellij plugin

ctrl-alt-S, then "Plugins" search for "String Manipulations"; install and reboot.

for instance, if you need to "escape XML" (that is transform reserve chars in "% bla ;" sequences :

File/new scratch file (or ctrl-alt-shift-ins), paste your XML, select all, right click "String manipulation", "escape xml"

Normally I used Notepad++ and the "XML Tools Plugin", but this seems more useful.

Wednesday, April 3, 2019

git synchronize repositories

It happens that an external Git repository has to be mirrored internally in a corporate git repository. This cloning and mirroring should include branches, tags, commit history etc. and be one-way (internal changes are lot upon synchronization)

Luckily you don't have to write special scripts, all is provided by git:

Let's make an experiment

in github I create a "gitclonesource" and a "gitclonedestination" empty repositories

mkdir gitclonetests
cd gitclonetests

#let's prepare the source
mkdir gitclonesource
cd gitclonesource
git init
echo "ciao" >
git add
git commit -m "first commit"
git remote add origin
git push -u origin master

#create branch
git checkout -b mybranch
echo "hello" >> mybranch.txt
git add mybranch.txt
git commit -am "added mybranch.txt"
git push --set-upstream origin mybranch

#create tag
git checkout master
git tag -a v1.4 -m "my version 1.4"
git push --tags

#now clone source and push to destination with all branches and tags
cd ..
#this will create a folder gitclonesource.git
git clone --bare
#when you cd, you will see a message BARE:master if using Git bash
cd gitclonesource.git/
git push --mirror

Counting objects: 7, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (7/7), 600 bytes | 200.00 KiB/s, done.
Total 7 (delta 0), reused 0 (delta 0)
 * [new branch]      master -> master
 * [new branch]      mybranch -> mybranch
 * [new tag]         v1.4 -> v1.4

and, lo and behold, in the gitclonedestination I can find my branch and the tag! All cloned in one go!

at this point you can cleanup the gitclonedestination.git:

cd ..
rm -rf gitclonedestination.git

Monday, April 1, 2019

WebLogic Security documentation JACC "Java Authorization Contract for Containers" java.lang.SecurityManager

Java Authentication Service Provider Interface for Containers (JASPIC)

Training Material:

Old book

Best Spring books

reblogging for my own reference, I am planning to read all those 5 books...

- Spring in Action 5
- Cloud Native Java
- Learning Spring Boot 2.0
- Spring 5 Recipes
- Spring Microservices in Action

I am already going through but I find it incredibly non-concise - lot of repeated stuff, very lengthy and boring coding sessions where you don't really see much new, lot of unnecessary verbosity. Not my style, I like crisp, focused, simple examples and just fundamental facts and concepts.