Skip to content

Commit 052dbb2

Browse files
Sonar code smell issue fixes (#4450)
Signed-off-by: Gino Augustine <[email protected]>
1 parent 1ea1ac6 commit 052dbb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+297
-322
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuruHelp.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,38 +56,38 @@ public static String getUsage() {
5656
System.lineSeparator() + System.lineSeparator());
5757
byFactory(AnalyzerGuru.getAnalyzerFactories().stream().
5858
collect(Collectors.toMap(f -> f.getClass().getSimpleName(), f -> f))).
59-
forEach((factory) -> {
59+
forEach(factory ->
6060
b.append(String.format("%-10s : %s%n",
6161
factory.fac.getClass().getSimpleName().replace("AnalyzerFactory", ""),
62-
factory.fac.getName() != null ? factory.fac.getName() : "N/A"));
63-
});
62+
factory.fac.getName() != null ? factory.fac.getName() : "N/A"))
63+
);
6464

6565
b.append(System.lineSeparator() + "AnalyzerGuru prefixes:" + System.lineSeparator());
66-
byKey(AnalyzerGuru.getPrefixesMap()).forEach((kv) -> {
66+
byKey(AnalyzerGuru.getPrefixesMap()).forEach(kv ->
6767
b.append(String.format("%-10s : %s%n", reportable(kv.key + '*'),
68-
reportable(kv.fac)));
69-
});
68+
reportable(kv.fac)))
69+
);
7070

7171
b.append(System.lineSeparator() + "AnalyzerGuru extensions:" + System.lineSeparator());
72-
byKey(AnalyzerGuru.getExtensionsMap()).forEach((kv) -> {
72+
byKey(AnalyzerGuru.getExtensionsMap()).forEach(kv ->
7373
b.append(String.format("*.%-7s : %s%n",
7474
reportable(kv.key.toLowerCase(Locale.ROOT)),
75-
reportable(kv.fac)));
76-
});
75+
reportable(kv.fac)))
76+
);
7777

7878
b.append(System.lineSeparator() + "AnalyzerGuru magic strings:" + System.lineSeparator());
79-
byFactory(AnalyzerGuru.getMagicsMap()).forEach((kv) -> {
79+
byFactory(AnalyzerGuru.getMagicsMap()).forEach(kv ->
8080
b.append(String.format("%-23s : %s%n", reportable(kv.key),
81-
reportable(kv.fac)));
82-
});
81+
reportable(kv.fac)))
82+
);
8383

8484
b.append(System.lineSeparator() + "AnalyzerGuru magic matchers:" + System.lineSeparator());
85-
AnalyzerGuru.getAnalyzerFactoryMatchers().forEach((m) -> {
85+
AnalyzerGuru.getAnalyzerFactoryMatchers().forEach(m -> {
8686
if (m.isPreciseMagic()) {
8787
b.append(reportable(m));
8888
}
8989
});
90-
AnalyzerGuru.getAnalyzerFactoryMatchers().forEach((m) -> {
90+
AnalyzerGuru.getAnalyzerFactoryMatchers().forEach(m -> {
9191
if (!m.isPreciseMagic()) {
9292
b.append(reportable(m));
9393
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/ada/AdaLexer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public void takeLiteral(String value, String className)
4646

4747
int off = 0;
4848
do {
49-
int w = 1, ri, ni, i;
50-
ri = value.indexOf("\r", off);
51-
ni = value.indexOf("\n", off);
49+
int w = 1, i;
50+
int ri = value.indexOf("\r", off);
51+
int ni = value.indexOf("\n", off);
5252
if (ri == -1 && ni == -1) {
5353
String sub = value.substring(off);
5454
offer(sub);
@@ -93,5 +93,6 @@ public void chkLOC() {
9393
* Subclasses must override to get the constant value created by JFlex to
9494
* represent SCOMMENT.
9595
*/
96+
@SuppressWarnings("java:S100")
9697
abstract int SCOMMENT();
9798
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/archive/BZip2Analyzer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut)
8888
if (path != null
8989
&& (path.endsWith(".bz2") || path.endsWith(".BZ2") || path.endsWith(".bz"))) {
9090
String newname = path.substring(0, path.lastIndexOf('.'));
91-
//System.err.println("BZIPPED OF = " + newname);
9291
try (InputStream in = bzSrc.getStream()) {
9392
fa = AnalyzerGuru.getAnalyzer(in, newname);
9493
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/archive/ZipMatcherBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public AnalyzerFactory isMagic(byte[] contents, InputStream in)
6868
in.reset();
6969

7070
int xoff = LOCHDRSIZ + LOCNAM(buf);
71-
int xoff_end = Math.min(len, xoff + LOCEXT(buf));
72-
while ((xoff < xoff_end) && (len - xoff >= XFHSIZ)) {
71+
int xoffEnd = Math.min(len, xoff + LOCEXT(buf));
72+
while ((xoff < xoffEnd) && (len - xoff >= XFHSIZ)) {
7373
int xfhid = SH(buf, xoff);
7474
if (xfhid == strictExtraFieldID()) {
7575
return forFactory();

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/perl/PerlLexer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public void hop(String capture) throws IOException {
427427
* @return true if a Here state was pushed
428428
*/
429429
public boolean maybeStartHere() throws IOException {
430-
if (hereSettings != null && hereSettings.size() > 0) {
430+
if (hereSettings != null && !hereSettings.isEmpty()) {
431431
HereDocSettings settings = hereSettings.peek();
432432
yypush(settings.state);
433433
disjointSpan(HtmlConsts.STRING_CLASS);
@@ -454,7 +454,7 @@ public boolean maybeEndHere(String capture) throws IOException {
454454

455455
offer(capture);
456456

457-
if (hereSettings.size() > 0) {
457+
if (!hereSettings.isEmpty()) {
458458
settings = hereSettings.peek();
459459
yybegin(settings.state);
460460
if (didZspan) {

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/plain/XMLAnalyzer.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.opengrok.indexer.analysis.WriteXrefArgs;
3939
import org.opengrok.indexer.analysis.XrefWork;
4040
import org.opengrok.indexer.analysis.Xrefer;
41-
import org.opengrok.indexer.configuration.RuntimeEnvironment;
4241
import org.opengrok.indexer.search.QueryBuilder;
4342

4443
/**
@@ -79,8 +78,6 @@ protected int getSpecializedVersionNo() {
7978
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException, InterruptedException {
8079
doc.add(new OGKTextField(QueryBuilder.FULL, getReader(src.getStream())));
8180

82-
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
83-
8481
if (xrefOut != null) {
8582
try (Reader in = getReader(src.getStream())) {
8683
WriteXrefArgs args = new WriteXrefArgs(in, xrefOut);

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/ruby/RubyLexer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public void hop(String capture) throws IOException {
350350
* @return true if a Here state was pushed
351351
*/
352352
public boolean maybeStartHere() throws IOException {
353-
if (dHead.hereSettings != null && dHead.hereSettings.size() > 0) {
353+
if (dHead.hereSettings != null && !dHead.hereSettings.isEmpty()) {
354354
HereDocSettings settings = dHead.hereSettings.peek();
355355
yypush(settings.state);
356356
disjointSpan(HtmlConsts.STRING_CLASS);
@@ -378,7 +378,7 @@ public boolean maybeEndHere(String capture) throws IOException {
378378

379379
offer(capture);
380380

381-
if (dHead.hereSettings.size() > 0) {
381+
if (!dHead.hereSettings.isEmpty()) {
382382
settings = dHead.hereSettings.peek();
383383
yybegin(settings.state);
384384
if (didZspan) {

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/verilog/VerilogLexer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ public void chkLOC() {
4646
* Subclasses must override to get the constant value created by JFlex to
4747
* represent COMMENT.
4848
*/
49+
@SuppressWarnings("java:S100")
4950
abstract int COMMENT();
5051

5152
/**
5253
* Subclasses must override to get the constant value created by JFlex to
5354
* represent SCOMMENT.
5455
*/
56+
@SuppressWarnings("java:S100")
5557
abstract int SCOMMENT();
5658
}

opengrok-indexer/src/main/java/org/opengrok/indexer/authorization/AuthorizationEntity.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ protected void processTargetGroupsAndProjects() {
445445
* Check the existence of the projects and issue a warning if there
446446
* is no such project.
447447
*/
448-
Project p;
449-
if ((p = Project.getByName(t)) == null) {
448+
if ( Project.getByName(t) == null) {
450449
LOGGER.log(Level.WARNING, "Configured project \"{0}\" in forProjects"
451450
+ " section for name \"{1}\" does not exist",
452451
new Object[]{t, getName()});
@@ -611,13 +610,13 @@ protected String setupToString(String prefix) {
611610
*/
612611
protected String targetsToString(String prefix) {
613612
StringBuilder builder = new StringBuilder();
614-
if (forGroups().size() > 0) {
613+
if (!forGroups().isEmpty()) {
615614
builder.append(prefix).append(" only for groups:\n");
616615
for (String x : forGroups()) {
617616
builder.append(prefix).append(" ").append(x).append("\n");
618617
}
619618
}
620-
if (forProjects().size() > 0) {
619+
if (!forProjects().isEmpty()) {
621620
builder.append(prefix).append(" only for projects:\n");
622621
for (String x : forProjects()) {
623622
builder.append(prefix).append(" ").append(x).append("\n");

opengrok-indexer/src/main/java/org/opengrok/indexer/authorization/AuthorizationPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public synchronized void load(Map<String, Object> parameters) {
118118
plugin.load(getCurrentSetup());
119119
setWorking();
120120
} catch (Throwable ex) {
121-
LOGGER.log(Level.SEVERE, "Plugin \"" + getName() + "\" has failed while loading with exception:", ex);
121+
LOGGER.log(Level.SEVERE, ex, () -> "Plugin \"" + getName() + "\" has failed while loading with exception:");
122122
setFailed();
123123
}
124124

@@ -144,7 +144,7 @@ public synchronized void unload() {
144144
plugin.unload();
145145
plugin = null;
146146
} catch (Throwable ex) {
147-
LOGGER.log(Level.SEVERE, "Plugin \"" + getName() + "\" has failed while unloading with exception:", ex);
147+
LOGGER.log(Level.SEVERE, ex, () -> "Plugin \"" + getName() + "\" has failed while unloading with exception:");
148148
}
149149
}
150150
}

0 commit comments

Comments
 (0)