Skip to content

Commit a2cb0f9

Browse files
Sonar Code Smell issue fixes (#4455)
Signed-off-by: Gino Augustine <[email protected]>
1 parent d6e53db commit a2cb0f9

Some content is hidden

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

46 files changed

+115
-27
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/Info.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
*
3232
* @author Trond Norbye
3333
*/
34-
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
3534
public final class Info {
3635
private static final Properties properties = new Properties();
3736

@@ -50,7 +49,7 @@ public final class Info {
5049
REVISION = properties.getProperty("changeset", UNKNOWN);
5150
REVISION_SHORT = properties.getProperty("changeset_short", UNKNOWN);
5251
} catch (IOException ioe) {
53-
throw new RuntimeException(ioe);
52+
throw new VersionInfoLoadException(ioe);
5453
}
5554
}
5655

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2023, Oracle and/or its affiliates.
22+
* Portions Copyright (c) 2023, Gino Augustine <[email protected]>.
23+
*/
24+
package org.opengrok.indexer;
25+
26+
/**
27+
* Runtime exception thrown if there is any error in loading opengrok version information file.
28+
*
29+
* @author Gino Augustine
30+
*/
31+
public class VersionInfoLoadException extends RuntimeException {
32+
private static final long serialVersionUID = 1L;
33+
34+
/**
35+
* Constructs a VersionInfoLoadException with the specified cause and a
36+
* detail message of {@code (cause==null ? null : cause.toString())}
37+
* (which typically contains the class and detail message of
38+
* {@code cause}). This constructor is useful for runtime exceptions
39+
* that are little more than wrappers for other throwables.
40+
*
41+
* @param cause the cause (which is saved for later retrieval by the
42+
* {@link #getCause()} method). (A {@code null} value is
43+
* permitted, and indicates that the cause is nonexistent or
44+
* unknown.)
45+
* @since 1.4
46+
*/
47+
public VersionInfoLoadException(Throwable cause) {
48+
super(cause);
49+
}
50+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* <p>
3737
* http://www.adaic.org/
3838
*/
39+
@SuppressWarnings("java:S110")
3940
public class AdaAnalyzer extends AbstractSourceCodeAnalyzer {
4041

4142
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public void takeLiteral(String value, String className)
4646

4747
int off = 0;
4848
do {
49-
int w = 1, i;
49+
int w = 1;
50+
int i;
5051
int ri = value.indexOf("\r", off);
5152
int ni = value.indexOf("\n", off);
5253
if (ri == -1 && ni == -1) {

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.io.IOException;
2828
import java.io.InputStream;
2929
import java.io.Writer;
30+
import java.util.Optional;
31+
3032
import org.apache.lucene.document.Document;
3133
import org.apache.lucene.document.Field;
3234
import org.apache.tools.bzip2.CBZip2InputStream;
@@ -81,22 +83,21 @@ protected int getSpecializedVersionNo() {
8183
@Override
8284
public void analyze(Document doc, StreamSource src, Writer xrefOut)
8385
throws IOException, InterruptedException {
84-
AbstractAnalyzer fa;
8586

86-
StreamSource bzSrc = wrap(src);
87-
String path = doc.get(QueryBuilder.PATH);
88-
if (path != null
89-
&& (path.endsWith(".bz2") || path.endsWith(".BZ2") || path.endsWith(".bz"))) {
90-
String newname = path.substring(0, path.lastIndexOf('.'));
87+
var optionalNewName = Optional.ofNullable(doc.get(QueryBuilder.PATH))
88+
.filter(path -> path.toUpperCase().endsWith(".BZ2") || path.endsWith(".bz"))
89+
.map(path -> path.substring(0, path.lastIndexOf('.')));
90+
if (optionalNewName.isPresent()) {
91+
StreamSource bzSrc = wrap(src);
92+
AbstractAnalyzer fa;
9193
try (InputStream in = bzSrc.getStream()) {
92-
fa = AnalyzerGuru.getAnalyzer(in, newname);
94+
fa = AnalyzerGuru.getAnalyzer(in, optionalNewName.get());
9395
}
9496
if (!(fa instanceof BZip2Analyzer)) {
95-
if (fa.getGenre() == Genre.PLAIN || fa.getGenre() == Genre.XREFABLE) {
96-
this.g = Genre.XREFABLE;
97-
} else {
98-
this.g = Genre.DATA;
99-
}
97+
this.g = Optional.ofNullable(fa.getGenre())
98+
.filter( genre -> genre == Genre.PLAIN || genre == Genre.XREFABLE)
99+
.map(genre -> Genre.XREFABLE)
100+
.orElse(Genre.DATA);
100101
fa.analyze(doc, bzSrc, xrefOut);
101102
if (doc.get(QueryBuilder.T) != null) {
102103
doc.removeField(QueryBuilder.T);

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/asm/AsmAnalyzer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
/**
3434
* Represents an analyzer for assembly language.
3535
*/
36+
@SuppressWarnings("java:S110")
3637
public class AsmAnalyzer extends AbstractSourceCodeAnalyzer {
3738

3839
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/c/CAnalyzer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*
3838
* @author Chandan
3939
*/
40+
@SuppressWarnings("java:S110")
4041
public class CAnalyzer extends AbstractSourceCodeAnalyzer {
4142

4243
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/c/CxxAnalyzer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*
3636
* @author Trond Norbye
3737
*/
38+
@SuppressWarnings("java:S110")
3839
public class CxxAnalyzer extends AbstractSourceCodeAnalyzer {
3940

4041
/**

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/clojure/ClojureAnalyzer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.opengrok.indexer.analysis.JFlexXref;
3131
import org.opengrok.indexer.analysis.plain.AbstractSourceCodeAnalyzer;
3232

33+
@SuppressWarnings("java:S110")
3334
public class ClojureAnalyzer extends AbstractSourceCodeAnalyzer {
3435

3536
protected ClojureAnalyzer(AnalyzerFactory factory) {

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/csharp/CSharpAnalyzer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*
3535
* @author Christoph Hofmann
3636
*/
37+
@SuppressWarnings("java:S110")
3738
public class CSharpAnalyzer extends AbstractSourceCodeAnalyzer {
3839

3940
protected CSharpAnalyzer(AnalyzerFactory factory) {

0 commit comments

Comments
 (0)