Skip to content

Commit 0826ee0

Browse files
authored
Merge pull request #3148 from idodeclare/bugfix/sonar_bugs
Fix another batch of Sonar-identified issues
2 parents 1c8c7ec + d26fc5a commit 0826ee0

File tree

22 files changed

+448
-147
lines changed

22 files changed

+448
-147
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/executables/ELFAnalyzer.java

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2018-2019, Chris Fraire <cfraire@me.com>.
22+
* Portions Copyright (c) 2018-2020, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.analysis.executables;
2525

@@ -193,23 +193,23 @@ private static class ELFHeader {
193193
// Word = int
194194
// un = unsignedBtye
195195

196-
public EI_Class ei_class;
197-
public EI_Data ei_data;
196+
EI_Class ei_class;
197+
EI_Data ei_data;
198198
@SuppressWarnings("unused")
199-
public int ei_version;
200-
public E_Type e_type;
201-
public E_Machine e_machine;
202-
public E_Version e_version;
203-
public int e_entry;
204-
public int e_phoff;
205-
public int e_shoff;
206-
public int e_flags;
207-
public int e_ehsize;
208-
public int e_phentsize;
209-
public int e_phnum;
210-
public int e_shentsize;
211-
public int e_shnum;
212-
public int e_shstrndx;
199+
int ei_version;
200+
E_Type e_type;
201+
E_Machine e_machine;
202+
E_Version e_version;
203+
int e_entry;
204+
int e_phoff;
205+
int e_shoff;
206+
int e_flags;
207+
int e_ehsize;
208+
int e_phentsize;
209+
int e_phnum;
210+
int e_shentsize;
211+
int e_shnum;
212+
int e_shstrndx;
213213

214214
ELFHeader(MappedByteBuffer fmap) throws IllegalArgumentException {
215215
if (fmap.get(ELFIdentification.EI_MAG0.value()) != 0x7f ||
@@ -256,46 +256,46 @@ public String toString() {
256256
}
257257

258258
private static class ELFSection {
259-
public static final int SHT_NULL = 0; /* Section header table entry unused */
260-
public static final int SHT_PROGBITS = 1; /* Program data */
261-
public static final int SHT_SYMTAB = 2; /* Symbol table */
262-
public static final int SHT_STRTAB = 3; /* String table */
263-
public static final int SHT_RELA = 4; /* Relocation entries with addends */
264-
public static final int SHT_HASH = 5; /* Symbol hash table */
265-
public static final int SHT_DYNAMIC = 6; /* Dynamic linking information */
266-
public static final int SHT_NOTE = 7; /* Notes */
267-
public static final int SHT_NOBITS = 8; /* Program space with no data (bss) */
268-
public static final int SHT_REL = 9; /* Relocation entries, no addends */
269-
public static final int SHT_SHLIB = 10; /* Reserved */
270-
public static final int SHT_DYNSYM = 11; /* Dynamic linker symbol table */
271-
public static final int SHT_INIT_ARRAY = 14; /* Array of constructors */
272-
public static final int SHT_FINI_ARRAY = 15; /* Array of destructors */
273-
public static final int SHT_PREINIT_ARRAY = 16; /* Array of pre-constructors */
274-
public static final int SHT_GROUP = 17; /* Section group */
275-
public static final int SHT_SYMTAB_SHNDX = 18; /* Extended section indices */
276-
public static final int SHT_NUM = 19; /* Number of defined types. */
277-
public static final int SHT_LOOS = 0x60000000; /* Start OS-specific */
278-
public static final int SHT_GNU_LIBLIST = 0x6ffffff7; /* Prelink library list */
279-
public static final int SHT_CHECKSUM = 0x6ffffff8; /* Checksum for DSO content. */
280-
public static final int SHT_LOSUNW = 0x6ffffffa; /* Sun-specific low bound. */
281-
public static final int SHT_SUNW_COMDAT = 0x6ffffffb;
282-
public static final int SHT_HISUNW = 0x6fffffff; /* Sun-specific high bound. */
283-
public static final int SHT_HIOS = 0x6fffffff; /* End OS-specific type */
284-
public static final int SHT_LOPROC = 0x70000000; /* Start of processor-specific */
285-
public static final int SHT_HIPROC = 0x7fffffff; /* End of processor-specific */
286-
public static final int SHT_LOUSER = 0x80000000; /* Start of application-specific */
287-
public static final int SHT_HIUSER = 0x8fffffff; /* End of application-specific */
288-
289-
public int sh_name;
290-
public int sh_type;
291-
public int sh_flags;
292-
public int sh_addr;
293-
public int sh_offset;
294-
public int sh_size;
295-
public int sh_link;
296-
public int sh_info;
297-
public int sh_addralign;
298-
public int sh_entsize;
259+
static final int SHT_NULL = 0; /* Section header table entry unused */
260+
static final int SHT_PROGBITS = 1; /* Program data */
261+
static final int SHT_SYMTAB = 2; /* Symbol table */
262+
static final int SHT_STRTAB = 3; /* String table */
263+
static final int SHT_RELA = 4; /* Relocation entries with addends */
264+
static final int SHT_HASH = 5; /* Symbol hash table */
265+
static final int SHT_DYNAMIC = 6; /* Dynamic linking information */
266+
static final int SHT_NOTE = 7; /* Notes */
267+
static final int SHT_NOBITS = 8; /* Program space with no data (bss) */
268+
static final int SHT_REL = 9; /* Relocation entries, no addends */
269+
static final int SHT_SHLIB = 10; /* Reserved */
270+
static final int SHT_DYNSYM = 11; /* Dynamic linker symbol table */
271+
static final int SHT_INIT_ARRAY = 14; /* Array of constructors */
272+
static final int SHT_FINI_ARRAY = 15; /* Array of destructors */
273+
static final int SHT_PREINIT_ARRAY = 16; /* Array of pre-constructors */
274+
static final int SHT_GROUP = 17; /* Section group */
275+
static final int SHT_SYMTAB_SHNDX = 18; /* Extended section indices */
276+
static final int SHT_NUM = 19; /* Number of defined types. */
277+
static final int SHT_LOOS = 0x60000000; /* Start OS-specific */
278+
static final int SHT_GNU_LIBLIST = 0x6ffffff7; /* Prelink library list */
279+
static final int SHT_CHECKSUM = 0x6ffffff8; /* Checksum for DSO content. */
280+
static final int SHT_LOSUNW = 0x6ffffffa; /* Sun-specific low bound. */
281+
static final int SHT_SUNW_COMDAT = 0x6ffffffb;
282+
static final int SHT_HISUNW = 0x6fffffff; /* Sun-specific high bound. */
283+
static final int SHT_HIOS = 0x6fffffff; /* End OS-specific type */
284+
static final int SHT_LOPROC = 0x70000000; /* Start of processor-specific */
285+
static final int SHT_HIPROC = 0x7fffffff; /* End of processor-specific */
286+
static final int SHT_LOUSER = 0x80000000; /* Start of application-specific */
287+
static final int SHT_HIUSER = 0x8fffffff; /* End of application-specific */
288+
289+
int sh_name;
290+
int sh_type;
291+
int sh_flags;
292+
int sh_addr;
293+
int sh_offset;
294+
int sh_size;
295+
int sh_link;
296+
int sh_info;
297+
int sh_addralign;
298+
int sh_entsize;
299299

300300
ELFSection(MappedByteBuffer fmap) {
301301
sh_name = fmap.getInt();
@@ -336,7 +336,7 @@ private enum ELFIdentification {
336336
this.value = value;
337337
}
338338

339-
public int value() {
339+
int value() {
340340
return this.value;
341341
}
342342
}
@@ -366,7 +366,7 @@ static EI_Class valueOf(byte value) throws IllegalArgumentException {
366366
}
367367
}
368368

369-
public int value() {
369+
int value() {
370370
return this.value;
371371
}
372372

@@ -397,7 +397,7 @@ static EI_Data valueOf(byte value) throws IllegalArgumentException {
397397
}
398398
}
399399

400-
public int value() {
400+
int value() {
401401
return this.value;
402402
}
403403
}
@@ -432,7 +432,7 @@ static E_Type valueOf(short value) {
432432
}
433433
}
434434

435-
public int value() {
435+
int value() {
436436
return this.value;
437437
}
438438

@@ -483,7 +483,7 @@ static E_Machine valueOf(short value) {
483483
}
484484
}
485485

486-
public int value() {
486+
int value() {
487487
return this.value;
488488
}
489489

@@ -519,7 +519,7 @@ static E_Version valueOf(int value) throws IllegalArgumentException {
519519
}
520520
}
521521

522-
public int value() {
522+
int value() {
523523
return this.value;
524524
}
525525

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2020, Chris Fraire <cfraire@me.com>.
2223
*/
2324
package org.opengrok.indexer.authorization;
2425

@@ -37,6 +38,7 @@
3738
import org.opengrok.indexer.configuration.RuntimeEnvironment;
3839
import org.opengrok.indexer.framework.PluginFramework;
3940
import org.opengrok.indexer.logger.LoggerFactory;
41+
import org.opengrok.indexer.web.Laundromat;
4042
import org.opengrok.indexer.web.Statistics;
4143

4244
/**
@@ -484,7 +486,7 @@ private boolean checkAll(HttpServletRequest request, String cache, Nameable enti
484486

485487
if (entity == null) {
486488
LOGGER.log(Level.WARNING, "entity was null for request with parameters: {}",
487-
request.getParameterMap());
489+
Laundromat.launderLog(request.getParameterMap()));
488490
return false;
489491
}
490492

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017-2018, Chris Fraire <cfraire@me.com>.
22+
* Portions Copyright (c) 2017-2018, 2020, Chris Fraire <cfraire@me.com>.
2323
*/
2424
package org.opengrok.indexer.history;
2525

@@ -226,8 +226,7 @@ String determineCurrentVersion(boolean interactive) throws IOException {
226226
}
227227

228228
private static class VobsHolder {
229-
230-
public static String[] vobs = runLsvob();
229+
static String[] vobs = runLsvob();
231230
}
232231

233232
private static String[] getAllVobs() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ static int copyBytes(BufferSink sink, InputStream in) throws IOException {
610610
}
611611

612612
static class HistoryRevResult {
613-
public boolean success;
614-
public int iterations;
613+
boolean success;
614+
int iterations;
615615
}
616616

617617
private class RepositoryDateFormat extends DateFormat {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2020, Chris Fraire <cfraire@me.com>.
2223
*/
2324
package org.opengrok.indexer.history;
2425

@@ -27,6 +28,7 @@
2728
import java.io.InputStream;
2829
import java.util.logging.Level;
2930
import java.util.logging.Logger;
31+
import javax.xml.XMLConstants;
3032
import javax.xml.parsers.ParserConfigurationException;
3133
import javax.xml.parsers.SAXParser;
3234
import javax.xml.parsers.SAXParserFactory;
@@ -70,9 +72,11 @@ public Annotation getAnnotation() {
7072
@Override
7173
public void processStream(InputStream input) throws IOException {
7274
SAXParserFactory factory = SAXParserFactory.newInstance();
73-
SAXParser saxParser = null;
75+
SAXParser saxParser;
7476
try {
7577
saxParser = factory.newSAXParser();
78+
saxParser.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); // Compliant
79+
saxParser.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); // compliant
7680
} catch (ParserConfigurationException | SAXException ex) {
7781
IOException err = new IOException("Failed to create SAX parser", ex);
7882
throw err;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017, Chris Fraire <cfraire@me.com>.
22+
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
2323
* Portions Copyright (c) 2020, Ric Harris <harrisric@users.noreply.github.com>.
2424
*/
2525
package org.opengrok.indexer.history;
@@ -37,6 +37,7 @@
3737
import java.util.logging.Level;
3838
import java.util.logging.Logger;
3939

40+
import javax.xml.XMLConstants;
4041
import javax.xml.parsers.SAXParser;
4142
import javax.xml.parsers.SAXParserFactory;
4243

@@ -152,13 +153,14 @@ public void characters(char[] arg0, int arg1, int arg2) {
152153

153154
/**
154155
* Initialize the SAX parser instance.
155-
* @throws HistoryException
156156
*/
157157
private void initSaxParser() throws HistoryException {
158158
SAXParserFactory factory = SAXParserFactory.newInstance();
159159
saxParser = null;
160160
try {
161161
saxParser = factory.newSAXParser();
162+
saxParser.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); // Compliant
163+
saxParser.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); // compliant
162164
} catch (Exception ex) {
163165
throw new HistoryException("Failed to create SAX parser", ex);
164166
}

opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/*
2121
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright 2011 Jens Elkner.
23-
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
23+
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
2424
*/
2525
package org.opengrok.indexer.index;
2626

@@ -97,7 +97,7 @@ public final class Indexer {
9797

9898
//whole app uses this separator
9999
public static final char PATH_SEPARATOR = '/';
100-
public static String PATH_SEPARATOR_STRING = Character.toString(PATH_SEPARATOR);
100+
public static final String PATH_SEPARATOR_STRING = Character.toString(PATH_SEPARATOR);
101101

102102
private static final String HELP_OPT_1 = "--help";
103103
private static final String HELP_OPT_2 = "-?";

0 commit comments

Comments
 (0)