Skip to content

Commit

Permalink
Merge pull request #3241 from c71n93/2251-fixing-sonar-violations
Browse files Browse the repository at this point in the history
Fix sonar reliability issues
  • Loading branch information
yegor256 authored Jul 29, 2024
2 parents 612380a + e15fe10 commit 5b1a1cf
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static Dependency randDep(final String scope) {
return DcsFake.dep(
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
String.valueOf(Math.abs(rand.nextInt())),
String.valueOf(rand.nextInt(Integer.MAX_VALUE)),
scope
);
}
Expand Down Expand Up @@ -125,7 +125,7 @@ private static Dependency randDep() {
return DcsFake.dep(
UUID.randomUUID().toString(),
UUID.randomUUID().toString(),
String.valueOf(Math.abs(rand.nextInt())),
String.valueOf(rand.nextInt(Integer.MAX_VALUE)),
scope
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String value() {

@Override
public CommitHash hash() {
return new CommitHash.ChConstant(this.name.label().get());
return new CommitHash.ChConstant(this.name.label().orElse(""));
}

@Override
Expand Down
37 changes: 18 additions & 19 deletions eo-maven-plugin/src/test/java/org/eolang/maven/PullMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,27 +295,26 @@ void doesNotPullInOfflineMode(@TempDir final Path tmp) throws IOException {

@Test
@CaptureLogs
void showsWhereNotFoundWasDiscoveredAt(@TempDir final Path tmp, final Logs out) {
void showsWhereNotFoundWasDiscoveredAt(@TempDir final Path tmp, final Logs out)
throws IOException {
final FakeMaven mvn = new FakeMaven(tmp)
.withProgram(
"+package com.example\n",
"# This is the default 64+ symbols comment in front of named abstract object.",
"[] > main",
" org.eolang.org > @"
)
.with(
"objectionaries",
new Objectionaries.Fake(
new OyRemote(
new ChRemote("master")
)
)
);
Assertions.assertThrows(
Exception.class,
() -> {
new FakeMaven(tmp)
.withProgram(
"+package com.example\n",
"# This is the default 64+ symbols comment in front of named abstract object.",
"[] > main",
" org.eolang.org > @"
)
.with(
"objectionaries",
new Objectionaries.Fake(
new OyRemote(
new ChRemote("master")
)
)
)
.execute(new FakeMaven.Pull());
},
() -> mvn.execute(new FakeMaven.Pull()),
"Pull mojo should fail, but it does not"
);
Assertions.assertTrue(
Expand Down
10 changes: 10 additions & 0 deletions eo-runtime/src/main/java/org/eolang/Dataized.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,21 @@ public final class Dataized {

/**
* Dataization level.
*
* @todo #2251:90min It is necessary to call {@link ThreadLocal#remove()} on
* {@link Dataized#LEVEL} variables to prevent memory leaks. We should either find a place
* where this variable can be removed, or, if this is not possible
* (see https://github.com/objectionary/eo/pull/1930), come up with another solution.
*/
private static final ThreadLocal<Integer> LEVEL = ThreadLocal.withInitial(() -> 0);

/**
* Max dataization level.
*
* @todo #2251:90min It is necessary to call {@link ThreadLocal#remove()} on
* {@link Dataized#MAX_LEVEL} variables to prevent memory leaks. We should either find a place
* where this variable can be removed, or, if this is not possible
* (see https://github.com/objectionary/eo/pull/1930), come up with another solution.
*/
private static final ThreadLocal<Integer> MAX_LEVEL =
ThreadLocal.withInitial(() -> Integer.getInteger("max.dataization.log", 3));
Expand Down
5 changes: 5 additions & 0 deletions eo-runtime/src/main/java/org/eolang/PhDefault.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public class PhDefault implements Phi, Cloneable {

/**
* Attributes nesting level.
*
* @todo #2251:90min It is necessary to call {@link ThreadLocal#remove()} on
* {@link PhDefault#NESTING} to prevent memory leaks. We should either find a place where this
* variable can be removed, or, if this is not possible
* (see https://github.com/objectionary/eo/pull/1930), come up with another solution.
*/
private static final ThreadLocal<Integer> NESTING = ThreadLocal.withInitial(() -> 0);

Expand Down
1 change: 1 addition & 0 deletions eo-runtime/src/main/java/org/eolang/PhPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public Phi take(final String name) {
} else {
res = new AtSetRho(this.objects.get().get(key), this, key).get();
}
this.objects.remove();
return res;
}

Expand Down
5 changes: 5 additions & 0 deletions eo-runtime/src/main/java/org/eolang/PhTraced.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public final class PhTraced implements Phi {
/**
* Cages that are currently being dataized. If one cage is being datazed, and
* it needs to be dataized inside current dataization, the locator of current object be here.
*
* @todo #2251:90min It is necessary to call {@link ThreadLocal#remove()} on
* {@link PhTraced#DATAIZING_CAGES} to prevent memory leaks. We should either find a
* place where this variable can be removed, or, if this is not possible
* (see https://github.com/objectionary/eo/pull/1930), come up with another solution.
*/
private static final ThreadLocal<Map<Integer, Integer>> DATAIZING_CAGES = ThreadLocal
.withInitial(HashMap::new);
Expand Down

4 comments on commit 5b1a1cf

@0pdd
Copy link

@0pdd 0pdd commented on 5b1a1cf Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2251-77d37465 discovered in eo-runtime/src/main/java/org/eolang/Dataized.java) and submitted as #3298. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 5b1a1cf Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2251-f49f0da1 discovered in eo-runtime/src/main/java/org/eolang/Dataized.java) and submitted as #3299. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 5b1a1cf Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2251-4b006ee2 discovered in eo-runtime/src/main/java/org/eolang/PhDefault.java) and submitted as #3300. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 5b1a1cf Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2251-bb889cd1 discovered in eo-runtime/src/main/java/org/eolang/PhTraced.java) and submitted as #3301. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.