Skip to content

Commit b893844

Browse files
committed
Merge branch 'master' of github.com:sdelamo/sergiodelamo.com
2 parents f5a8df4 + 26574a0 commit b893844

File tree

4 files changed

+233
-2
lines changed

4 files changed

+233
-2
lines changed

pages/projects.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ date_modified: 2021-09-23T06:19:05+01:00
99

1010
# Projects
1111

12-
## 🎥 Youtube Channel
12+
## 🎥 Video
1313

14-
I have a [Youtube Channel](https://www.youtube.com/channel/UC-ZOt0P3l97wtL_fNbi9DvQ) with similar content to this website.
14+
I have a [Youtube Channel](https://www.youtube.com/channel/UC-ZOt0P3l97wtL_fNbi9DvQ) with similar content to this website.
15+
16+
I created a Micronaut Fundamentals, a video course available for free on [Oracle MyLearn](https://mylearn.oracle.com/ou/course/micronaut-fundamentals/151938/) with an OCI Free Learning Subscription.
1517

1618
## ✏️ Writing
1719

posts/2025-10-23-jcasbin.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: jCasbin
3+
summary: > jCasbin is a powerful and efficient open-source access control library for Java projects. It provides support for enforcing authorization based on various access control models.
4+
date_published: 2025-10-23T15:13:18+01:00
5+
keywords:acl
6+
external_url: https://github.com/casbin/jcasbin
7+
> jCasbin is a powerful and efficient open-source access control library for Java projects. It provides support for enforcing authorization based on various access control models.
8+
---
9+
10+
# [%title]
11+
12+
[%summary]
13+
14+
15+
16+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: Micronaut Fundamentals
3+
summary: During this year, I recorded Micronaut Fundamentals, a video course available for free on [Oracle MyLearn](https://mylearn.oracle.com/ou/course/micronaut-fundamentals/151938/) with an OCI Free Learning Subscription.
4+
date_published: 2025-10-29T14:46:22+01:00
5+
keywords: micronaut,video,course
6+
external_url: https://mylearn.oracle.com/ou/course/micronaut-fundamentals/151938/
7+
---
8+
9+
# [%title]
10+
11+
[%summary]
12+
13+
It is a 7-hour and 37-minute course covering the following topics:
14+
15+
- Introduction to Micronaut
16+
- Micronaut Documentation
17+
- Creating your first Micronaut application
18+
- Using Micronaut in popular IDEs
19+
- Exploring a Micronaut application
20+
- Micronaut Build Plugins
21+
- Micronaut Test
22+
- Micronaut Core Concepts
23+
- Serialization
24+
- Application Events
25+
- Source Code Generation
26+
- Configuration
27+
- Dependency Injection
28+
- HTTP Client
29+
- HTTP Server
30+
- Filters
31+
- Management Endpoints
32+
- Logging
33+
- Validation
34+
- Error formats
35+
- Error handling
36+
- OpenAPI
37+
- Packaging and distribution
38+
- GraalVM Native Image
39+
- Graal Development Kit for Micronaut
40+
41+
Announcement in [Oracle Blog](https://blogs.oracle.com/java/post/micronaut-fundamentals).

posts/2025-11-21-null-away.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
title: Micronaut NullAway and JSPecify
3+
summary: In this blog post, I show you how to configure a Micronaut 4 application to use JSpecify and NullAway to protect you from NPEs (Null Pointer Exceptions).
4+
date_published: 2025-11-21T11:32:42+01:00
5+
keywords:micronaut,nullaway,jspecify
6+
---
7+
8+
# [%title]
9+
10+
[%summary]
11+
12+
## [NullAway](http://github.com/uber/NullAway):
13+
14+
> NullAway is a tool to help eliminate NullPointerExceptions (NPEs) in your Java code. To use NullAway, first add @Nullable annotations in your code wherever a field, method parameter, or return value may be null. Given these annotations, NullAway performs a series of type-based, local checks to ensure that any pointer that gets dereferenced in your code cannot be null.
15+
16+
17+
## JSpecify Dependency
18+
19+
Since Micronaut 4.10, Micronaut BOM contains the JSpecify dependency. Thus, you can add the following dependency to your project without specifying the version:
20+
21+
```xml
22+
<dependency>
23+
<groupId>org.jspecify</groupId>
24+
<artifactId>jspecify</artifactId>
25+
</dependency>
26+
```
27+
28+
## NullAway with Gradle
29+
30+
[GitHub Repository with a Gradle Micronaut Application which uses `NullAway`](https://github.com/sdelamo/micronaut-gradle-nullaway-demo/tree/main)
31+
32+
To use [NullAway](http://github.com/uber/NullAway) in a Gradle Micronaut Application. You need to add the [Gradle error prone plugin](https://github.com/tbroyer/gradle-errorprone-plugin) and such configuration:
33+
34+
35+
```kotlin
36+
plugins {
37+
...
38+
..
39+
.
40+
id("net.ltgt.errorprone") version "4.3.0"
41+
}
42+
dependencies {
43+
...
44+
..
45+
.
46+
implementation("org.jspecify:jspecify")
47+
errorprone("com.uber.nullaway:nullaway:0.12.12")
48+
errorprone("com.google.errorprone:error_prone_core:2.44.0")
49+
}
50+
tasks.withType<JavaCompile>().configureEach {
51+
options.errorprone {
52+
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
53+
option("NullAway:AnnotatedPackages", example.micronaut")
54+
if (name.lowercase().contains("test")) {
55+
disable("NullAway")
56+
}
57+
}
58+
}
59+
```
60+
61+
- `check("NullAway", CheckSeverity.ERROR)` sets `NullAway` issues to the error level.
62+
- `option("NullAway:AnnotatedPackages", “example.micronaut”)` tells `NullAway` that source code in packages under the `example.micronaut` namespace should be checked for null dereferences and proper usage of `@Nullable ` annotations, and that class files in these packages should be assumed to have correct usage of `@Nullable`.
63+
- Then, it disables `NullAway` on test code.
64+
65+
[These instructions are described in the NullAway README.md file](https://github.com/uber/NullAway?tab=readme-ov-file#java-non-android).
66+
67+
## NullAway with Maven
68+
[GitHub Repository with a Maven Micronaut Application which uses `NullAway`](https://github.com/sdelamo/micronaut-maven-nullaway-demo/tree/main)
69+
70+
```xml
71+
72+
<?xml version="1.0" encoding="UTF-8"?>
73+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
74+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
75+
...
76+
..
77+
.
78+
<properties>
79+
...
80+
..
81+
.
82+
<error-prone.version>2.29.2</error-prone.version>
83+
<nullaway.version>0.12.12</nullaway.version>
84+
</properties>
85+
...
86+
..
87+
.
88+
<dependencies>
89+
<dependency>
90+
<groupId>org.jspecify</groupId>
91+
<artifactId>jspecify</artifactId>
92+
<version>1.0.0</version>
93+
</dependency>
94+
...
95+
..
96+
.
97+
</dependencies>
98+
<build>
99+
<plugins>
100+
...
101+
..
102+
.
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-compiler-plugin</artifactId>
106+
<configuration>
107+
<compilerArgs>
108+
<arg>-XDcompilePolicy=simple</arg>
109+
<arg>--should-stop=ifError=FLOW</arg>
110+
<arg>-Xplugin:ErrorProne -Xep:NullAway:ERROR -XepOpt:NullAway:AnnotatedPackages=example.micronaut</arg>
111+
<arg>-Amicronaut.processing.group=mn.maven.jspecify</arg>
112+
<arg>-Amicronaut.processing.module=mn-maven-jspecify</arg>
113+
</compilerArgs>
114+
<annotationProcessorPaths combine.children="append">
115+
<path>
116+
<groupId>com.google.errorprone</groupId>
117+
<artifactId>error_prone_core</artifactId>
118+
<version>${error-prone.version}</version>
119+
</path>
120+
<path>
121+
<groupId>com.uber.nullaway</groupId>
122+
<artifactId>nullaway</artifactId>
123+
<version>${nullaway.version}</version>
124+
</path>
125+
<!-- Existing Micronaut processors -->
126+
...
127+
..
128+
.
129+
</annotationProcessorPaths>
130+
</configuration>
131+
</plugin>
132+
</plugins>
133+
</build>
134+
</project>
135+
```
136+
137+
The above example adds two annotation processors. [Error Prone](https://errorprone.info/docs/flags#maven) and [NullAway](https://github.com/uber/NullAway/wiki/Configuration).
138+
139+
The previous code sample [configures `NullAway`](https://github.com/uber/NullAway/wiki/Configuration):
140+
141+
142+
- `-XepOpt:NullAway:AnnotatedPackages` sets the list of packages that should be considered properly annotated according to the NullAway convention
143+
- `-Xep:NullAway:ERROR` sets the NullAway check severity to ERROR, which should cause compilation to fail when `NullAway` violations are found.
144+
145+
As [described in the error prone Maven documentation](https://errorprone.info/docs/installation#maven), I added a `.mvn/jvmconfig` file with the following content:
146+
147+
```
148+
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
149+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
150+
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
151+
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
152+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
153+
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
154+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
155+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
156+
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
157+
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
158+
```
159+
160+
A failure looks like:
161+
162+
```
163+
[INFO] ------------------------------------------------------------------------
164+
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.14.1:compile (default-compile) on project mn-maven-jspecify: Compilation failure
165+
[ERROR] /Users/sdelamo/github/sdelamo/micronaut-maven-nullaway-demo/src/main/java/example/micronaut/GreetingController.java:[21,39] [NullAway] dereferenced expression greetingService.greet() is @Nullable
166+
[ERROR] (see http://t.uber.com/nullaway )
167+
[ERROR]
168+
[ERROR] -> [Help 1]
169+
[ERROR]
170+
```
171+
172+

0 commit comments

Comments
 (0)