Skip to content

Commit c89157e

Browse files
Feature/sonar (#207)
Sonar warnings Deprecated FPDateUtils (bør fjernes overalt)
1 parent 31c8d0c commit c89157e

File tree

9 files changed

+34
-21
lines changed

9 files changed

+34
-21
lines changed

felles/sikkerhet/sikkerhet/src/main/java/no/nav/vedtak/isso/config/ServerInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public final class ServerInfo {
1919
private String callbackUrl;
2020
private String cookieDomain = cookieDomain(schemeHostPort);
2121

22-
private static volatile ServerInfo instance = null;
22+
private static ServerInfo instance;
2323

2424
ServerInfo() {
2525

felles/sikkerhet/sikkerhet/src/main/java/no/nav/vedtak/sikkerhet/ContextPathHolder.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22

33
public class ContextPathHolder {
44

5-
private static volatile ContextPathHolder instance = null;
5+
private static ContextPathHolder instance = null;
66
private final String contextPath;
77

88
private ContextPathHolder(String contextPath) {
99
this.contextPath = contextPath;
1010
}
1111

1212
public static ContextPathHolder instance() {
13-
if (instance == null) {
14-
throw new IllegalStateException();
13+
synchronized (ContextPathHolder.class) {
14+
if (instance == null) {
15+
throw new IllegalStateException();
16+
}
17+
return instance;
1518
}
16-
return instance;
1719
}
1820

1921
public static ContextPathHolder instance(String contextPath) {

felles/sikkerhet/sikkerhet/src/main/java/no/nav/vedtak/sikkerhet/oidc/OidcTokenValidatorProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class OidcTokenValidatorProvider {
3232
private static final Set<IdentType> interneIdentTyper = new HashSet<>(Arrays.asList(IdentType.InternBruker, IdentType.Systemressurs));
3333
private static final Set<IdentType> eksterneIdentTyper = new HashSet<>(Arrays.asList(IdentType.EksternBruker));
3434

35-
private static volatile OidcTokenValidatorProvider instance = null;
35+
private static OidcTokenValidatorProvider instance;
3636
private final Map<String, OidcTokenValidator> validators;
3737

3838
private OidcTokenValidatorProvider() {

felles/sikkerhet/sikkerhet/src/main/java/no/nav/vedtak/sikkerhet/pdp/PdpConsumerImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public XacmlResponseWrapper evaluate(XacmlRequestBuilder request) {
115115
JsonObject execute(JsonObject request) {
116116
HttpPost post = new HttpPost(pdpUrl);
117117
post.setHeader("Content-type", MEDIA_TYPE);
118-
post.setEntity(new StringEntity(request.toString(), Charset.forName("UTF-8")));
118+
post.setEntity(new StringEntity(request.toString(), java.nio.charset.StandardCharsets.UTF_8));
119119

120120
LOG.trace("PDP-request: {}", request);
121121

@@ -143,7 +143,7 @@ JsonObject execute(JsonObject request) {
143143
return response.getElement2();
144144
}
145145
if (HttpStatus.SC_UNAUTHORIZED == statusCode) {
146-
throw PdpFeil.FACTORY.autentiseringFeilerEtterReinstansiering(System.getenv("HOSTNAME")).toException();
146+
throw PdpFeil.FACTORY.autentiseringFeilerEtterReinstansiering(System.getenv("HOSTNAME")).toException(); // NOSONAR
147147
}
148148
}
149149
throw PdpFeil.FACTORY.httpFeil(statusCode, response.getElement1().getReasonPhrase()).toException();

felles/testutilities/src/main/java/no/nav/vedtak/felles/testutilities/UnitTestConfiguration.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class UnitTestConfiguration {
2121

2222
public static void loadUnitTestProperties() {
2323
Properties properties = getUnitTestProperties();
24-
if (properties == null) {
24+
if (properties.isEmpty()) {
2525
// ingenting nytt
2626
return;
2727
}
@@ -36,7 +36,7 @@ public static void loadToSystemProperties(Properties properties, boolean overwri
3636
Properties systemProperties = System.getProperties();
3737
for (Entry<Object, Object> entry : properties.entrySet()) {
3838
if (overwriteSystemProperties || !systemProperties.containsKey(entry.getKey())) {
39-
log.info(entry.getKey() + " = " + entry.getValue()); //$NON-NLS-1$
39+
log.info(entry.getKey() + " = " + entry.getValue()); // NOSONAR ok for test konfig
4040
systemProperties.setProperty((String) entry.getKey(), (String) entry.getValue());
4141
}
4242
}

felles/testutilities/src/main/java/no/nav/vedtak/felles/testutilities/db/FlywayKonfig.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public boolean migrerDb() {
101101
}
102102

103103
private boolean skalBrukeCustomClean(DataSource dataSource) {
104-
try {
105-
String databaseProductName = dataSource.getConnection().getMetaData().getDatabaseProductName();
104+
try (var conn = dataSource.getConnection()) {
105+
String databaseProductName = conn.getMetaData().getDatabaseProductName();
106106
return "PostgreSQL".equalsIgnoreCase(databaseProductName);
107107
} catch (SQLException e) {
108108
throw FeilFactory.create(DbMigreringFeil.class).kanIkkeDetektereDatbaseType(e).toException();
@@ -125,7 +125,7 @@ private Properties lesFlywayPlaceholders() {
125125
private void clean(DataSource dataSource, String username) {
126126
try (Connection c = dataSource.getConnection();
127127
Statement stmt = c.createStatement()) {
128-
stmt.execute("drop owned by " + username.replaceAll("[^a-zA-Z0-9_-]", "_"));
128+
stmt.execute("drop owned by " + username.replaceAll("[^a-zA-Z0-9_-]", "_")); // NOSONAR ok her, test konfig
129129
} catch (SQLException e) {
130130
throw new IllegalStateException("Kunne ikke kjøre clean på db", e);
131131
}

felles/util/src/main/java/no/nav/vedtak/util/FPDateUtil.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import java.time.Period;
99
import java.time.temporal.ChronoUnit;
1010

11-
import no.nav.vedtak.konfig.PropertyUtil;
12-
1311
/**
1412
* Returner funksjonelt tidsoffset, Brukes med LocalDate og LocalDateTime. eks. LocalDate.now(FPDateUtil.getOffset)
13+
* @deprecated Overstyring av clock er ikke et test behov lenger (gjøres bedre gjennom docker/kubernetes).
1514
*/
15+
@Deprecated(forRemoval = true)
1616
public class FPDateUtil {
1717
private static volatile ClockProvider clockProvider;
1818

@@ -39,7 +39,7 @@ public static ClockProvider getCurrentClockProvider() {
3939

4040
/**
4141
* Ikke bruk denne metoden direkte, kall på iDag() eller nå()
42-
* Metoden vil bli private i en fremtidig versjon
42+
* @deprecated Metoden vil bli private i en fremtidig versjon
4343
*/
4444
@Deprecated
4545
public static Clock getOffset() {
@@ -86,7 +86,7 @@ public static class SystemConfiguredClockProvider implements ClockProvider {
8686
private volatile Clock clock;
8787

8888
public SystemConfiguredClockProvider() {
89-
String offsetPeriode = PropertyUtil.getProperty(PROPERTY_KEY_OFFSET_PERIODE);
89+
String offsetPeriode = getProperty(PROPERTY_KEY_OFFSET_PERIODE);
9090

9191
if (offsetPeriode != null && !offsetPeriode.isEmpty()) {
9292
this.offsetPeriod = Period.parse(offsetPeriode);
@@ -128,5 +128,16 @@ private LocalDate periodToLocalDate(Period period) {
128128
.plusMonths(period.getMonths())
129129
.plusDays(period.getDays());
130130
}
131+
132+
/** Gjør eget oppslag her for å ikke koble denne koden til EnvironmentProperty eller annet rammeverk. */
133+
private String getProperty(String key) {
134+
// sjekk system props først.
135+
String val = System.getProperty(key); // NOSONAR
136+
if (val == null) {
137+
// sjekk env hvis ikke fins som system prop
138+
val = System.getenv(key.toUpperCase().replace('.', '_')); // NOSONAR
139+
}
140+
return val;
141+
}
131142
}
132143
}

integrasjon/oppgave-rest-klient/src/main/java/no/nav/vedtak/felles/integrasjon/oppgave/v1/request/AktørId.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ public class AktørId implements Serializable, Comparable<AktørId> {
1717
private static final String VALID_REGEXP = "^\\d{13}$";
1818

1919
private static final Pattern VALID = Pattern.compile(VALID_REGEXP, Pattern.CASE_INSENSITIVE);
20-
private static AtomicLong DUMMY_AKTØRID = new AtomicLong(1000000000000L);
20+
private static final AtomicLong DUMMY_AKTØRID = new AtomicLong(1000000000000L);
2121

2222
@JsonValue
2323
@NotNull
2424
@javax.validation.constraints.Pattern(regexp = VALID_REGEXP, message = "aktørId ${validatedValue} har ikke gyldig verdi ( pattern '{regexp}')")
2525
private String aktørId; // NOSONAR
2626

27-
protected AktørId() {
27+
protected AktørId() { // NOSONAR
2828
// for hibernate
2929
}
3030

integrasjon/rest-klient/src/main/java/no/nav/vedtak/felles/integrasjon/rest/RestClientSupportProdusent.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
5050
String param = he.getName();
5151
String value = he.getValue();
5252
if (value != null && param.equalsIgnoreCase("timeout")) {
53-
return Long.parseLong(value) * 1000;
53+
return Long.parseLong(value) * 1000L;
5454
}
5555
}
56-
return seconds * 1000;
56+
return seconds * 1000L;
5757
}
5858
};
5959
return myStrategy;

0 commit comments

Comments
 (0)