Skip to content

Commit 667c06e

Browse files
Fix Sonar codesmell issues (#4460)
Signed-off-by: Gino Augustine <[email protected]>
1 parent 2f0c0f8 commit 667c06e

File tree

51 files changed

+663
-641
lines changed

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

+663
-641
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ public static void writeXref(AnalyzerFactory factory, Reader in,
703703
* @param file file object, used for logging only
704704
* @throws java.io.IOException if an error occurs while creating the output
705705
*/
706+
@SuppressWarnings("java:S5443")
706707
public static void writeDumpedXref(String contextPath,
707708
AnalyzerFactory factory, Reader in, Writer out,
708709
@Nullable Definitions defs, Annotation annotation, Project project, File file) throws IOException {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,6 @@ private void readTags(CtagsReader reader) throws InterruptedException {
591591
throw new InterruptedException("readLine()");
592592
}
593593

594-
//log.fine("Tagline:-->" + tagLine+"<----ONELINE");
595594
if (tagLine == null) {
596595
if (!junitTesting) {
597596
LOGGER.warning("ctags: Unexpected end of file!");

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ public enum tagFields {
102102
// NAMESPACE("namespace"), //this is not defined in above format docs, but both universal and exuberant ctags use it
103103
// PROGRAM("program"), //this is not defined in above format docs, but both universal and exuberant ctags use it
104104
SIGNATURE("signature");
105-
// STRUCT("struct"),
106-
// TYPEREF("typeref"),
107-
// UNION("union");
108105

109106
//NOTE: if you edit above, always consult below charCmpEndOffset
110107
private final String name;
@@ -381,7 +378,8 @@ private CpatIndex bestIndexOfTag(int lineno, String whole, String str) {
381378
String origWhole = whole;
382379

383380
int t = tabSize;
384-
int s, e;
381+
int s;
382+
int e;
385383

386384
int woff = strictIndexOf(whole, str);
387385
if (woff < 0) {
@@ -440,7 +438,8 @@ private CpatIndex bestIndexOfArg(int lineno, String whole, String arg) {
440438
}
441439

442440
int t = tabSize;
443-
int s, e;
441+
int s;
442+
int e;
444443

445444
// First search arg as-is in the current `whole' -- strict then lax.
446445
int woff = strictIndexOf(whole, arg);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut)
9393
String path = doc.get(QueryBuilder.PATH);
9494
if (path != null && path.toLowerCase(Locale.ROOT).endsWith(".gz")) {
9595
String newname = path.substring(0, path.length() - 3);
96-
//System.err.println("GZIPPED OF = " + newname);
9796
try (InputStream gzis = gzSrc.getStream()) {
9897
fa = AnalyzerGuru.getAnalyzer(gzis, newname);
9998
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/document/DocumentMatcher.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ public AnalyzerFactory isMagic(byte[] contents, InputStream in)
124124
if (!foundLF) {
125125
return null;
126126
}
127-
if (bomLength > 0) {
128-
if (in.skip(bomLength) != bomLength) {
129-
in.reset();
130-
return null;
131-
}
127+
if (bomLength > 0 && in.skip(bomLength) != bomLength) {
128+
in.reset();
129+
return null;
132130
}
133131

134132
// read line-by-line for a first few lines

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ protected boolean processStack(Nameable entity,
260260
}
261261
} catch (AuthorizationException ex) {
262262
// Propagate up so that proper HTTP error can be given.
263-
LOGGER.log(Level.FINEST, "got authorization exception: " + ex.getMessage());
263+
LOGGER.log(Level.FINEST, () -> "got authorization exception: " + ex.getMessage());
264264
throw ex;
265265
} catch (Throwable ex) {
266266
LOGGER.log(Level.WARNING,

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Configuration.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public final class Configuration {
187187
private short contextLimit; // initialized non-zero in ctor
188188
private short contextSurround;
189189
private boolean lastEditedDisplayMode;
190-
private String CTagsExtraOptionsFile;
190+
private String cTagsExtraOptionsFile;
191191
private int scanningDepth;
192192
private int nestingMaximum;
193193
private Set<String> allowedSymlinks;
@@ -220,7 +220,7 @@ public final class Configuration {
220220

221221
private boolean mergeCommitsEnabled;
222222

223-
public static final double defaultRamBufferSize = 16;
223+
public static final double DEFAULT_RAM_BUFFER_SIZE = 16;
224224

225225
/**
226226
* The directory hierarchy depth to limit the scanning for repositories.
@@ -261,19 +261,19 @@ public final class Configuration {
261261
* Upper bound for number of threads used for performing multi-project
262262
* searches. This is total for the whole webapp.
263263
*/
264-
private int MaxSearchThreadCount;
264+
private int maxSearchThreadCount;
265265

266266
/**
267267
* Upper bound for number of threads used for getting revision contents.
268268
* This is total for the whole webapp.
269269
*/
270-
private int MaxRevisionThreadCount;
270+
private int maxRevisionThreadCount;
271271

272272
/**
273273
* Upper bound for number of threads used for getting directory entries.
274274
* This is total for the whole webapp.
275275
*/
276-
private int MaxDirectoryListingThreadCount;
276+
private int maxDirectoryListingThreadCount;
277277

278278
/**
279279
* If false, do not display listing or projects/repositories on the index page.
@@ -556,7 +556,6 @@ public Configuration() {
556556
setApiTimeout(300); // 5 minutes
557557
setAuthenticationTokens(new HashSet<>());
558558
setAuthorizationWatchdogEnabled(false);
559-
//setBugPage("http://bugs.myserver.org/bugdatabase/view_bug.do?bug_id=");
560559
setBugPattern("\\b([12456789][0-9]{6})\\b");
561560
setCachePages(5);
562561
setCanonicalRoots(new HashSet<>());
@@ -604,19 +603,16 @@ public Configuration() {
604603
setProjects(new ConcurrentHashMap<>());
605604
setQuickContextScan(true);
606605
//below can cause an outofmemory error, since it is defaulting to NO LIMIT
607-
setRamBufferSize(defaultRamBufferSize); //MB
606+
setRamBufferSize(DEFAULT_RAM_BUFFER_SIZE); //MB
608607
setRemoteScmSupported(RemoteSCM.OFF);
609608
setRepositories(new ArrayList<>());
610-
//setReviewPage("http://arc.myserver.org/caselog/PSARC/");
611609
setReviewPattern("\\b(\\d{4}/\\d{3})\\b"); // in form e.g. PSARC 2008/305
612610
setRevisionMessageCollapseThreshold(200);
613611
setScanningDepth(DEFAULT_SCANNING_DEPTH); // default depth of scanning for repositories
614612
setScopesEnabled(true);
615613
setSourceRoot(null);
616-
//setTabSize(4);
617614
setTagsEnabled(false);
618615
setUseHistoryCacheForDirectoryListing(true);
619-
//setUserPage("http://www.myserver.org/viewProfile.jspa?username=");
620616
// Set to empty string, so we can append it to the URL unconditionally later.
621617
setUserPageSuffix("");
622618
setWebappLAF("default");
@@ -1289,11 +1285,11 @@ public Path getDtagsEftarPath() {
12891285
}
12901286

12911287
public String getCTagsExtraOptionsFile() {
1292-
return CTagsExtraOptionsFile;
1288+
return cTagsExtraOptionsFile;
12931289
}
12941290

12951291
public void setCTagsExtraOptionsFile(String filename) {
1296-
this.CTagsExtraOptionsFile = filename;
1292+
this.cTagsExtraOptionsFile = filename;
12971293
}
12981294

12991295
public Set<String> getAllowedSymlinks() {
@@ -1345,27 +1341,27 @@ public void setFoldingEnabled(boolean foldingEnabled) {
13451341
}
13461342

13471343
public int getMaxSearchThreadCount() {
1348-
return MaxSearchThreadCount;
1344+
return maxSearchThreadCount;
13491345
}
13501346

13511347
public void setMaxSearchThreadCount(int count) {
1352-
this.MaxSearchThreadCount = count;
1348+
this.maxSearchThreadCount = count;
13531349
}
13541350

13551351
public int getMaxRevisionThreadCount() {
1356-
return MaxRevisionThreadCount;
1352+
return maxRevisionThreadCount;
13571353
}
13581354

13591355
public void setMaxRevisionThreadCount(int count) {
1360-
this.MaxRevisionThreadCount = count;
1356+
this.maxRevisionThreadCount = count;
13611357
}
13621358

13631359
public int getMaxDirectoryListingThreadCount() {
1364-
return MaxDirectoryListingThreadCount;
1360+
return maxDirectoryListingThreadCount;
13651361
}
13661362

13671363
public void setMaxDirectoryListingThreadCount(int count) {
1368-
this.MaxDirectoryListingThreadCount = count;
1364+
this.maxDirectoryListingThreadCount = count;
13691365
}
13701366

13711367
public boolean isProjectsEnabled() {

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/ConfigurationHelp.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
public class ConfigurationHelp {
4848

4949
private static final String XML_COMMENT_START = " <!-- ";
50+
private static final String USER_DEFINED_KEY = "user-defined-key";
51+
private static final String USER_DEFINED_VALUE = "user-specified-value";
52+
private static final String NOT_SUPPORTED_MSG = "Not supported yet for ";
53+
5054

5155
private ConfigurationHelp() {
5256
}
@@ -136,7 +140,7 @@ private static Object getSampleValue(Method setter, Object defaultValue) {
136140
} else if (setter.getName().equals("setReviewPattern")) {
137141
return "Sample Issue \\#(\\d+)";
138142
} else if (paramType == String.class) {
139-
return "user-specified-value";
143+
return USER_DEFINED_VALUE;
140144
} else if (paramType == int.class) {
141145
return 1 + (int) defaultValue;
142146
} else if (paramType == long.class) {
@@ -158,9 +162,9 @@ private static Object getSampleValue(Method setter, Object defaultValue) {
158162
return getSampleSetValue(genType);
159163
} else if (paramType == AuthorizationStack.class) {
160164
AuthorizationStack astck = new AuthorizationStack(
161-
AuthControlFlag.REQUIRED, "user-specified-value");
165+
AuthControlFlag.REQUIRED, USER_DEFINED_VALUE);
162166
astck.add(new AuthorizationPlugin(AuthControlFlag.REQUISITE,
163-
"user-specified-value"));
167+
USER_DEFINED_VALUE));
164168
return astck;
165169
} else if (paramType == Filter.class) {
166170
Filter flt = new Filter();
@@ -198,7 +202,7 @@ private static Object getSampleListValue(Type genType) {
198202
Type actType = genParamType.getActualTypeArguments()[0];
199203

200204
if (actType != RepositoryInfo.class) {
201-
throw new UnsupportedOperationException("Not supported yet for " + actType);
205+
throw new UnsupportedOperationException(NOT_SUPPORTED_MSG + actType);
202206
}
203207
return null;
204208
}
@@ -216,24 +220,24 @@ private static Object getSampleMapValue(Type genType) {
216220
if (actType0 == String.class) {
217221
if (actType1 == String.class) {
218222
Map<String, String> strmap = new TreeMap<>();
219-
strmap.put("user-defined-key", "user-defined-value");
223+
strmap.put(USER_DEFINED_KEY, "user-defined-value");
220224
res = strmap;
221225
} else if (actType1 == Project.class) {
222226
Map<String, Project> strmap = new TreeMap<>();
223-
String nm = "user-defined-key";
227+
String nm = USER_DEFINED_KEY;
224228
strmap.put(nm, getSampleProject(nm));
225229
res = strmap;
226230
} else if (actType1 == Group.class) {
227231
Map<String, Group> strmap = new TreeMap<>();
228-
String nm = "user-defined-key";
232+
String nm = USER_DEFINED_KEY;
229233
strmap.put(nm, getSampleGroup(nm));
230234
res = strmap;
231235
} else {
232236
throw new UnsupportedOperationException(
233-
"Not supported yet for " + actType0 + " " + actType1);
237+
NOT_SUPPORTED_MSG + actType0 + " " + actType1);
234238
}
235239
} else {
236-
throw new UnsupportedOperationException("Not supported yet for " +
240+
throw new UnsupportedOperationException(NOT_SUPPORTED_MSG +
237241
actType0 + " " + actType1);
238242
}
239243
return res;
@@ -262,7 +266,7 @@ private static Object getSampleSetValue(Type genType) {
262266
prjset.add(p);
263267
res = prjset;
264268
} else {
265-
throw new UnsupportedOperationException("Not supported yet for " +
269+
throw new UnsupportedOperationException(NOT_SUPPORTED_MSG +
266270
actType);
267271
}
268272
return res;

opengrok-indexer/src/main/java/org/opengrok/indexer/history/ClearCaseRepository.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,30 @@ String determineCurrentVersion(CommandTimeoutType cmdType) throws IOException {
228228

229229
private static class VobsHolder {
230230
static String[] vobs = runLsvob();
231+
private static String[] runLsvob() {
232+
if (testRepo.isWorking()) {
233+
Executor exec = new Executor(
234+
new String[]{testRepo.RepoCommand, "lsvob", "-s"});
235+
int rc;
236+
if ((rc = exec.exec(true)) == 0) {
237+
String output = exec.getOutputString();
238+
239+
if (output == null) {
240+
LOGGER.log(Level.SEVERE,
241+
"\"cleartool lsvob -s\" output was null");
242+
return new String[0];
243+
}
244+
String sep = System.getProperty("line.separator");
245+
String[] vobs = output.split(Pattern.quote(sep));
246+
LOGGER.log(Level.CONFIG, "Found VOBs: {0}",
247+
Arrays.asList(vobs));
248+
return vobs;
249+
}
250+
LOGGER.log(Level.SEVERE,
251+
"\"cleartool lsvob -s\" returned non-zero status: {0}", rc);
252+
}
253+
return new String[0];
254+
}
231255
}
232256

233257
private static String[] getAllVobs() {
@@ -237,31 +261,6 @@ private static String[] getAllVobs() {
237261
private static final ClearCaseRepository testRepo
238262
= new ClearCaseRepository();
239263

240-
private static String[] runLsvob() {
241-
if (testRepo.isWorking()) {
242-
Executor exec = new Executor(
243-
new String[]{testRepo.RepoCommand, "lsvob", "-s"});
244-
int rc;
245-
if ((rc = exec.exec(true)) == 0) {
246-
String output = exec.getOutputString();
247-
248-
if (output == null) {
249-
LOGGER.log(Level.SEVERE,
250-
"\"cleartool lsvob -s\" output was null");
251-
return new String[0];
252-
}
253-
String sep = System.getProperty("line.separator");
254-
String[] vobs = output.split(Pattern.quote(sep));
255-
LOGGER.log(Level.CONFIG, "Found VOBs: {0}",
256-
Arrays.asList(vobs));
257-
return vobs;
258-
}
259-
LOGGER.log(Level.SEVERE,
260-
"\"cleartool lsvob -s\" returned non-zero status: {0}", rc);
261-
}
262-
return new String[0];
263-
}
264-
265264
@Override
266265
boolean hasHistoryForDirectories() {
267266
return true;

opengrok-indexer/src/main/java/org/opengrok/indexer/history/RazorRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ private File pathTranslation(File file, String intermediateElements,
333333

334334
@Override
335335
boolean isRepositoryFor(File file, CommandTimeoutType cmdType) {
336-
File f = new File(file, ".razor");
336+
File f = new File(file, RAZOR_DIR);
337337
return f.exists() && f.isDirectory();
338338
}
339339

0 commit comments

Comments
 (0)