Fixes sonar bugs & vulnerabilities:

createNewFile not required with Files.write "In other words, it opens the file for writing, creating the file if it doesn't exist, --"

https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#write(java.nio.file.Path,%20byte[],%20java.nio.file.OpenOption...)
This commit is contained in:
Rsl1122 2017-08-16 10:42:00 +03:00
parent 156aef8ce4
commit 6a29bfae16
5 changed files with 10 additions and 27 deletions

View File

@ -22,6 +22,7 @@ import java.nio.file.Files;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
@ -83,11 +84,15 @@ public class Locale {
}
private void writeNewDefaultLocale() throws IOException {
final int length = messages.keySet().stream()
Optional<String> key = messages.keySet().stream()
.map(Msg::getIdentifier)
.sorted(new StringLengthComparator())
.findFirst()
.get().length() + 2;
.findFirst();
if (!key.isPresent()) {
throw new IllegalStateException("Locale has not been loaded.");
}
final int length = key.get().length() + 2;
List<String> lines = messages.entrySet().stream()
.sorted(new LocaleEntryComparator())
.map(entry -> getSpacedIdentifier(entry.getKey().getIdentifier(), length) + "|| " + entry.getValue().toString())

View File

@ -80,11 +80,4 @@ public enum Html {
}
return returnValue;
}
/**
* @param html Sets the HTML String
*/
public void setHtml(String html) {
this.html = html;
}
}

View File

@ -124,8 +124,6 @@ public class ExportUtility {
playerFolder.mkdirs();
File inspectHtmlFile = new File(playerFolder, "index.html");
inspectHtmlFile.createNewFile();
Files.write(inspectHtmlFile.toPath(), Collections.singletonList(inspectHtml));
} catch (IOException e) {
Log.toLog("Export.writeInspectHtml: " + name, e);
@ -148,7 +146,6 @@ public class ExportUtility {
.replace(HtmlUtils.getInspectUrl(""), "../player/");
File analysisHtmlFile = new File(serverFolder, "index.html");
Log.debug("Export", "Analysis Page File: " + analysisHtmlFile.getAbsolutePath());
analysisHtmlFile.createNewFile();
Files.write(analysisHtmlFile.toPath(), Collections.singletonList(analysisHtml));
}
@ -157,7 +154,6 @@ public class ExportUtility {
playersFolder.mkdirs();
File playersHtmlFile = new File(playersFolder, "index.html");
Log.debug("Export", "Players Page File: " + playersHtmlFile.getAbsolutePath());
playersHtmlFile.createNewFile();
Files.write(playersHtmlFile.toPath(), Collections.singletonList(playersHtml));
}

View File

@ -1,5 +1,6 @@
package main.java.com.djrapitops.plan.utilities.metrics;
import com.djrapitops.plugin.api.TimeAmount;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@ -203,7 +204,7 @@ public class Metrics {
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
Bukkit.getScheduler().runTask(plugin, () -> submitData());
}
}, 1000 * 60 * 5, 1000 * 60 * 30);
}, TimeAmount.MINUTE.ms() * 5, TimeAmount.MINUTE.ms() * 30);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
// WARNING: Just don't do it!

View File

@ -44,18 +44,6 @@ public class HtmlTest {
assertEquals(expResult, result);
}
/**
*
*/
@Test
public void testSetHtml() {
Html instance = Html.SPAN;
String expResult = "Test</span>";
instance.setHtml(expResult);
String result = instance.parse();
assertEquals(expResult, result);
}
/**
*
*/