Skip to content

Commit

Permalink
Bug 582308 Add description information to snapshot history or details
Browse files Browse the repository at this point in the history
Avoid blank outline page if notes file is unreadable.
Also correct other uses of canRead() without isFile().

Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=582308
Change-Id: I6a847ff41b97681e8c682599468278ebd558981b
  • Loading branch information
ajohnson1 committed Sep 22, 2023
1 parent 3742c84 commit 094627d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,7 @@ public Remap(Pattern skipPattern, Pattern avoidPattern, boolean matchFields, boo
*/
public void loadMapping(File mapFile, boolean undo) throws IOException
{
if (mapFile != null && mapFile.canRead())
if (mapFile != null && mapFile.canRead() && mapFile.isFile())
{
Properties p = new Properties();
// Properties always written in ISO8859_1, so use stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ static Class<?> getClass(String cn1, String cn2) throws LinkageError
{
f = new File(f, "lib"); //$NON-NLS-1$
f = new File(f, "tools.jar"); //$NON-NLS-1$
if (f.canRead())
if (f.canRead() && f.isFile())
{
try
{
Expand Down Expand Up @@ -1118,7 +1118,7 @@ private List<File> progress(File udir, Collection<File> previous, int nfiles, lo

private static synchronized File getAgentJar() throws IOException
{
if (agentJar == null || !agentJar.canRead())
if (agentJar == null || !agentJar.canRead() || !agentJar.isFile())
{
agentJar = makeAgentJar();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public File acquireDump(VmInfo info, File preferredLocation, IProgressListener l
}
listener.done();
File file = new File(filename);
if (!file.canRead())
if (!file.canRead() || !file.isFile())
{
// Does it looks like an error message?
if (err.length() > 0 || ss.length > 1)
Expand Down Expand Up @@ -832,7 +832,7 @@ private boolean isIBMDumpType(DumpType t)

static synchronized File getExecJar() throws IOException
{
if (execJar == null || !execJar.canRead())
if (execJar == null || !execJar.canRead() || !execJar.isFile())
{
String jarname = "org.eclipse.mat.ibmexecdumps"; //$NON-NLS-1$
// Must add all classes in IBMDumpProvider.java
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2010, 2021 IBM Corporation
* Copyright (c) 2010, 2023 IBM Corporation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -196,7 +196,7 @@ File jextract(File preferredDump, boolean compress, List<File>dumps, File udir,
.getString("IBMSystemDumpProvider.ReturnCode"), jextract.getAbsolutePath(), exitCode, errorBuf.toString())); //$NON-NLS-1$
}

if (!dumpout.canRead()) { throw new FileNotFoundException(MessageFormat.format(Messages
if (!(dumpout.canRead() && dumpout.isFile())) { throw new FileNotFoundException(MessageFormat.format(Messages
.getString("IBMSystemDumpProvider.ReturnCode"), result.getPath(), errorBuf.toString())); //$NON-NLS-1$
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2020 SAP AG and IBM Corporation.
* Copyright (c) 2008, 2023 SAP AG and IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -240,7 +240,7 @@ else if (queryResult.getSubject() instanceof DisplayFileResult)
File p = r.getFile().getParentFile();
File styles = new File(p, "styles.css"); //$NON-NLS-1$
File stylesDark = new File(p, "styles-dark.css"); //$NON-NLS-1$
if (styles.canWrite() && stylesDark.canRead())
if (styles.canWrite() && stylesDark.canRead() && stylesDark.isFile())
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UncheckedIOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -598,59 +599,51 @@ public void run()
* snapshot resource.
* @param resourcePath The editor file (snapshot or index file).
* @return The contents of the notes file, lines separated by \n.
* @throws {@link UncheckedIOException} for some IO errors.
*/
public static String readNotes(File resourcePath)
{
try
if (resourcePath != null)
{
if (resourcePath != null)
File notesFile = getDefaultNotesFile(resourcePath);
if (notesFile.canRead() && notesFile.isFile())
{
File notesFile = getDefaultNotesFile(resourcePath);
if (notesFile.canRead())
try (FileInputStream fileInput = new FileInputStream(notesFile))
{
FileInputStream fileInput = new FileInputStream(getDefaultNotesFile(resourcePath));
BufferedReader myInput = new BufferedReader(new InputStreamReader(fileInput, NOTES_ENCODING));

try
{
BufferedReader myInput = new BufferedReader(new InputStreamReader(fileInput, NOTES_ENCODING));

try
{
String s;
StringBuffer b = new StringBuffer();
while ((s = myInput.readLine()) != null)
{
b.append(s);
b.append("\n");//$NON-NLS-1$
}
return b.toString();
}
finally
String s;
StringBuffer b = new StringBuffer();
while ((s = myInput.readLine()) != null)
{
try
{
myInput.close();
}
catch (IOException ignore)
{}
b.append(s);
b.append("\n");//$NON-NLS-1$
}
}
return b.toString();
}
finally
{
fileInput.close();
try
{
myInput.close();
}
catch (IOException ignore)
{}
}
}
catch (FileNotFoundException e)
{
throw new UncheckedIOException(notesFile.getPath(), e);
}
catch (IOException e)
{
throw new UncheckedIOException(notesFile.getPath(), e);
}
}

return null;
}
catch (FileNotFoundException e)
{
throw new RuntimeException(e);
}
catch (IOException e)
{
throw new RuntimeException(e);
}
return null;
}

private static void saveNotes(File resource, String notes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.File;
import java.io.Serializable;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -462,7 +463,15 @@ private String getNotes(SnapshotInfo info)

private String getNotes(File snapshotFile)
{
String notes = NotesView.readNotes(snapshotFile);
String notes;
try
{
notes = NotesView.readNotes(snapshotFile);
}
catch (UncheckedIOException e)
{
return null;
}
// Just use the first line
if (notes != null)
return notes.split("\n", 2)[0]; //$NON-NLS-1$
Expand Down

0 comments on commit 094627d

Please sign in to comment.