Skip to content

Commit

Permalink
small sonar suggested fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xpromache committed Nov 1, 2020
1 parent 4c910bc commit 66cfbc5
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 26 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
**/org/yamcs/protobuf/**,
**/org/yamcs/yarch/streamsql/StreamSqlParser*,
**/org/yamcs/ui/packetviewer/FilterParser*
**/org/yamcs/examples/**
</sonar.exclusions>
</properties>

Expand Down
7 changes: 4 additions & 3 deletions simulator/src/main/java/org/yamcs/simulator/CfdpReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ private void processEofPacket(EofPacket packet) {
private void saveFile() {
try {
File f = File.createTempFile("cfdp", "");
FileOutputStream fw = new FileOutputStream(f);
fw.write(cfdpDataFile.getData());
fw.close();
try (FileOutputStream fw = new FileOutputStream(f)) {
fw.write(cfdpDataFile.getData());
log.info("CFDP file saved in {}", f.getAbsolutePath());
}
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public synchronized void pollServer() throws ClientException {

if (i + 1 < connectionAttempts) {
try {
Thread.sleep(retryDelay);
this.wait(retryDelay);
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
}
Expand Down
4 changes: 1 addition & 3 deletions yamcs-core/src/main/java/org/yamcs/TmPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ public void setInvalid() {
}

public void setInvalid(boolean invalid) {
if (invalid) {
status = invalid ? status | STATUS_MASK_INVALID : status & ~STATUS_MASK_INVALID;
}
status = invalid ? status | STATUS_MASK_INVALID : status & ~STATUS_MASK_INVALID;
}

public boolean isInvalid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public void listCommands(Context ctx, ListCommandsRequest request, Observer<List
}

sqlb.descend(desc);
sqlb.limit(pos, limit + 1); // one more to detect hasMore
sqlb.limit(pos, limit + 1l); // one more to detect hasMore

ListCommandsResponse.Builder responseb = ListCommandsResponse.newBuilder();
StreamFactory.stream(instance, sqlb.toString(), sqlb.getQueryArguments(), new StreamSubscriber() {
Expand Down
16 changes: 8 additions & 8 deletions yamcs-core/src/main/java/org/yamcs/utils/GlobFileFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
import java.util.stream.Stream;

/**
* Finds a list of files according to a glob pattern.
Expand Down Expand Up @@ -75,14 +76,13 @@ private void findMatchingFiles(Path current, ListIterator<Path> pitr) throws Unc

if (isPattern(patterns)) {
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + patterns);
try {
Files.list(current)
.filter(p -> incrIoCount())
.map(p -> p.getFileName())
.filter(p -> matcher.matches(p))
.map(p -> current.resolve(p))
.filter(p -> Files.isDirectory(p) == pitr.hasNext())
.forEach(p -> findMatchingFiles(p, pitr));
try (Stream<Path> files =Files.list(current)){
files.filter(p -> incrIoCount())
.map(p -> p.getFileName())
.filter(p -> matcher.matches(p))
.map(p -> current.resolve(p))
.filter(p -> Files.isDirectory(p) == pitr.hasNext())
.forEach(p -> findMatchingFiles(p, pitr));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ protected boolean bulkDeleteFromPartitions(List<Partition> partitions, IndexFilt

// all partitions will have the same database, just use the same one
RdbPartition p1 = (RdbPartition) partitions.get(0);
FlushOptions flushOptions = new FlushOptions();

YRDB rdb;
try {
rdb = tablespace.getRdb(p1.dir, false);
Expand All @@ -257,22 +257,18 @@ protected boolean bulkDeleteFromPartitions(List<Partition> partitions, IndexFilt
throw new YarchException(e);
}

try {
try(FlushOptions flushOptions = new FlushOptions()) {
for (Partition p : partitions) {
RdbPartition rp = (RdbPartition) p;

DbRange dbRange = getDeleteDbRange(rp.tbsIndex, tableRange);
rdb.getDb().deleteRange(dbRange.rangeStart, dbRange.rangeEnd);

// rdb.getDb().compactRange(dbRange.rangeStart, ByteArrayUtils.plusOne(dbRange.rangeEnd));
}

rdb.getDb().flush(flushOptions);

} catch (RocksDBException e) {
throw new YarchException(e);
} finally {
flushOptions.close();
tablespace.dispose(rdb);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ public XtceStaxReader() {
public SpaceSystem readXmlDocument(String fileName) throws XMLStreamException, IOException {
this.fileName = fileName;
log.info("Parsing XTCE file {}", fileName);
xmlEventReader = initEventReader(fileName);
xmlEvent = null;
SpaceSystem spaceSystem = null;
try {
try (InputStream in = new FileInputStream(new File(fileName))){
xmlEventReader = initEventReader(in);
while (true) {
xmlEvent = xmlEventReader.nextEvent();
int eventType = xmlEvent.getEventType();
Expand Down Expand Up @@ -3940,8 +3940,7 @@ private void skipToTheEnd(String sectionName) throws XMLStreamException, Illegal
* @throws FileNotFoundException
* @throws XMLStreamException
*/
private XMLEventReader initEventReader(String filename) throws FileNotFoundException, XMLStreamException {
InputStream in = new FileInputStream(new File(filename));
private XMLEventReader initEventReader(InputStream in) throws XMLStreamException {
XMLInputFactory factory = XMLInputFactory.newInstance();
// Merge multiple character data blocks into a single event (e.g. algorithm text)
factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
Expand Down

0 comments on commit 66cfbc5

Please sign in to comment.