Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ protected String getFileName(final String name) {
* the exception
*/
public String getContents(final IFile file) throws Exception { // NOPMD
InputStream inputStream = file.getContents();
try {
try (InputStream inputStream = file.getContents()) {
byte[] buffer = new byte[TWO_KILO_BYTES];
int bytesRead;
StringBuffer b = new StringBuffer();
Expand All @@ -195,8 +194,6 @@ public String getContents(final IFile file) throws Exception { // NOPMD
}
} while (bytesRead != -1);
return b.toString();
} finally {
inputStream.close();
}
}

Expand Down Expand Up @@ -251,18 +248,8 @@ public ResourceSet getResourceSet() {
public EObject getModel(final String fileName) throws Exception { // NOPMD
IFile file = getFile(fileName);
Resource resource = get(XtextResourceSet.class).createResource(uri(file));
InputStream s = null;
try {
s = file.getContents();
try (InputStream s = file.getContents()) {
resource.load(s, null);
} finally {
if (s != null) {
try {
s.close();
} catch (IOException e) {
LOGGER.info("Failed to close test file " + fileName);
}
}
}
assertEquals(0, resource.getErrors().size(), resource.getErrors().toString());
return resource.getContents().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -91,8 +89,6 @@
@SuppressWarnings({"restriction", "nls"})
class CheckExtensionGenerator {
// CHECKSTYLE:ON
private static final Logger LOGGER = LogManager.getLogger(CheckExtensionGenerator.class);

static final String PREFERENCE_PLUGIN_XML_FILENAME = "PluginXmlFilename";
static final String STANDARD_PLUGIN_FILENAME = ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR;
static final String STANDARD_FRAGMENT_FILENAME = ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR;
Expand Down Expand Up @@ -504,30 +500,18 @@ private void mergeManifest(final CheckCatalog catalog, final IProgressMonitor mo
final IFile file = PDEProject.getManifest(project);

if (file.exists() && catalog.getGrammar() != null) {
InputStream fileContents = null;
try {
fileContents = file.getContents();
try (InputStream fileContents = file.getContents()) {
MergeableManifest2 manifest = new MergeableManifest2(fileContents, project.getName());
fileContents.close();
manifest.addRequiredBundles(new GrammarHelper(catalog.getGrammar()).getRequiredBundleSymbolicNames());
if (manifest.isModified()) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
manifest.write(os);
os.close();
file.setContents(new ByteArrayInputStream(os.toByteArray()), false, false, monitor);
}
} catch (IOException e) {
throw new WrappedException(e);
} catch (CoreException e) {
throw new WrappedException(e);
} finally {
if (fileContents != null) {
try {
fileContents.close();
} catch (IOException e) {
LOGGER.warn("Could not close the Manifest file after modifying it.", e);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected boolean setDocumentContent(final IDocument document, final IEditorInpu
protected void setDocumentContentQuietly(final XtextGMFDocument document, final InputStream contentStream, final String encoding) throws CoreException {
Reader in = null;

try {
try { // NOPMD UseTryWithResources - conditional close: closes in (if created) or contentStream (caller's)
String actualEncoding = encoding;
if (actualEncoding == null) {
actualEncoding = getDefaultEncoding();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ private void addTemplatesFromFile(final URL templates) {
if (templates != null) {
TemplateReaderWriter reader = new TemplateReaderWriter();
try {
InputStream openStream = templates.openStream();
try {
try (InputStream openStream = templates.openStream()) {
TemplatePersistenceData[] datas = reader.read(openStream, null);
int templateCounter = 0;
for (TemplatePersistenceData data : datas) {
Expand All @@ -106,8 +105,6 @@ private void addTemplatesFromFile(final URL templates) {
internalAdd(data);
}
}
} finally {
openStream.close();
}
} catch (IOException e) {
LOG.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static byte[] getSeparator(final String encoding) {
public static byte[] readFullStream(final InputStream input) throws IOException {
InputStream readStream = null;
boolean wrappedInput = false;
try {
try { // NOPMD UseTryWithResources - only closes when we created the wrapper, not the caller's stream
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[INPUT_BUFFER_SIZE];
if (!(input instanceof BufferedInputStream)) {
Expand Down
1 change: 0 additions & 1 deletion ddk-configuration/pmd/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
<exclude name="PreserveStackTrace"/><!--TODO-->
<exclude name="UnnecessaryWarningSuppression"/> <!--Experimental, too many false positives-->
<exclude name="UnusedLocalVariable"/><!--Checkstyle-->
<exclude name="UseTryWithResources"/><!--TODO-->
<exclude name="JUnit5TestShouldBePackagePrivate"/>
</rule>
<rule ref="category/java/bestpractices.xml/UnusedFormalParameter">
Expand Down