Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 340446 - Can't open phd if txt file exists in same directory
Summary: Can't open phd if txt file exists in same directory
Status: RESOLVED FIXED
Alias: None
Product: MAT
Classification: Tools
Component: Core (show other bugs)
Version: 1.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 1.8.1   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-18 11:49 EDT by Brian Peacock CLA
Modified: 2018-08-23 16:00 EDT (History)
1 user (show)

See Also:


Attachments
Here is a patch to do what is described in the bugzilla (4.22 KB, patch)
2011-03-18 11:49 EDT, Brian Peacock CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Peacock CLA 2011-03-18 11:49:07 EDT
Build Identifier: 

If a txt file exists in the same directory as the phd file, and the txt file is not a valid javacore, then it will fail with:

Error opening heap dump 'bp.phd'. Check the error log for further details.
Error opening heap dump 'bp.phd'. Check the error log for further details.
Unable to read dump /data/dumps/bp/bp.phd metafile /data/dumps/bp/bp.txt in DTFJ format DTFJ-PHD (java.io.IOException)
Unable to read dump /data/dumps/bp/bp.phd metafile /data/dumps/bp/bp.txt in DTFJ format DTFJ-PHD
Error parsing Javacore (java.io.IOException)
Error parsing Javacore
Not a javacore file. First line: this is some stuff (com.ibm.dtfj.javacore.parser.framework.parser.ParserException)
Not a javacore file. First line: this is some stuff

This is because the txt file is considered to be a javacore even though it isn't, and it will be passed as the metaFile to the DTFJ ImageFactory.getImage().
This will then fail with the exception described above. The fix is to catch any IOException, then retry without the metaFile. This will cure any problem that has occurred with a bad metaFile. If the IOException was actually something to do with the PHD itself, the second invocation of ImageFactory.getImage() will fail with the same Exception which will be caught and handled in the correct way.

Reproducible: Always
Comment 1 Brian Peacock CLA 2011-03-18 11:49:57 EDT
Created attachment 191521 [details]
Here is a patch to do what is described in the bugzilla
Comment 2 Andrew Johnson CLA 2011-03-21 06:01:03 EDT
I'm not convinced we need this. It doubles the time to report an error if the main dump file is corrupt. I haven't heard of a problem with people creating a text file of the same base name as the dump. The MAT notes view creates a file called dumpname.notes.txt which doesn't cause problems.

DTFJ 1.5 won't read 1.4.2 javacore dumps, but that is unlikely to cause a problem as by default the heap dump and java dumps are named heapdump*.phd and javacore*.txt, so MAT will not pass both dumps to DTFJ. The PHD reader silently ignores the associated javacore it cannot read.
Comment 3 Brian Peacock CLA 2011-03-28 10:01:17 EDT
I think this is all down to how people work.

I have a number of directories that each contain a number of dumps. A single directory will contain everything concerned with a particular issue that I am working on.

Let's assume I have 3 heapdumps in the directory. I want to keep a few notes on each dump reminding my what I was doing when each dump was created. The 3 heapdumps are called:

heapdump.20110211.135004.3802.0002.phd
heapdump.20110218.122113.5445.0002.phd
heapdump.20110311.152435.7882.0002.phd

Cleverly, MAT names all it's indices so they have the same basic naming convention and so to list all the files associated with the first heapdump once MAT has run I would type:

ls heapdump.20110211.135004.3802.0002.*
(Yes, I'm using Linux, but just replace ls with dir if you're a Windows person)

Thus, if I was writing some information about the first dump I've got in the habit of giving the file an extension of .txt (probably back from the old DOS days, although lots of editors used to default to .txt for text files) and thus to make sure I can get all the information along with this extra information using the same ls command I would create a file called:

heapdump.20110211.135004.3802.0002.txt

... and thus the problem occurs.

... and I have had this problem a couple of times already hence I wrote this fix.

Personally, I think the extra time required to fail is negligible and thus the downside is very small.
Comment 4 Eclipse Genie CLA 2018-08-23 12:19:50 EDT
New Gerrit change created: https://git.eclipse.org/r/127949
Comment 6 Andrew Johnson CLA 2018-08-23 16:00:46 EDT
Okay, I'll fix this.

For the record, I've not use the supplied patch, but implemented it myself.