JoseArthurSoares / essencium-backend

Essencium Backend is a software library built on top of Spring Boot that allows developers to quickly get started on new software projects. Essencium provides, for example, a fully implemented role-rights concept as well as various field-tested solutions for access management and authentication.
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Refactor: Dodgy code > JwtTokenService.java > Metodo: isAccessTokenValid > Evitar capturar NullPointerException no método isAccessTokenValid #16

Closed felipegangorra closed 6 months ago

felipegangorra commented 6 months ago

Do not catch NullPointerException like

Class: JwtTokenService (de.frachtwerk.essencium.backend.service) line 238

Method: isAccessTokenValid (de.frachtwerk.essencium.backend.service.JwtTokenService.isAccessTokenValid(String, String))

Priority:      Medium Confidence Dodgy code

NullPointerException caught According to SEI Cert rule ERR08-J NullPointerException should not be caught. Handling NullPointerException is considered an inferior alternative to null-checking. This non-compliant code catches a NullPointerException to see if an incoming parameter is null: boolean hasSpace(String m) { try { String ms[] = m.split(" "); return names.length != 1; } catch (NullPointerException e) { return false; } } A compliant solution would use a null-check as in the following example: boolean hasSpace(String m) { if (m == null) return false; String ms[] = m.split(" "); return names.length != 1; }