Skip to content

Commit b70a9e2

Browse files
committed
Fixed nullptr exception on nonxisting file handling.
1 parent c77a538 commit b70a9e2

File tree

1 file changed

+97
-95
lines changed
  • eclipse-plugin/eclipse/cc.codechecker.eclipse.plugin/src/cc/codechecker/plugin/report

1 file changed

+97
-95
lines changed

eclipse-plugin/eclipse/cc.codechecker.eclipse.plugin/src/cc/codechecker/plugin/report/PlistParser.java

Lines changed: 97 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -33,99 +33,101 @@
3333
* Class for parsing the analysis result plist files.
3434
*/
3535
public class PlistParser/* implements Runnable */{
36-
IProject project;
37-
38-
public PlistParser(IProject project) {
39-
this.project = project;
40-
}
41-
42-
/**
43-
* Parses exactly one .plist file.
44-
*
45-
* @param pathToFile
46-
* The file to be parsed.
47-
* @throws Exception
48-
*/
49-
public SearchList parsePlist(File file, SearchList sl) {
50-
List<ReportInfo> riList = new ArrayList<>();
51-
52-
NSDictionary dict;
53-
try {
54-
dict = (NSDictionary) PropertyListParser.parse(file);
55-
NSObject[] sourceFiles = ((NSArray) dict.objectForKey("files")).getArray();
56-
NSObject[] diagnostics = ((NSArray) dict.objectForKey("diagnostics")).getArray();
57-
58-
for (NSObject diagnostic : diagnostics) {
59-
NSDictionary diag = (NSDictionary) diagnostic;
60-
String checkerName = ((NSString) diag.get("check_name")).getContent();
61-
String description = ((NSString) diag.get("description")).getContent();
62-
63-
NSObject[] path = ((NSArray) diag.objectForKey("path")).getArray();
64-
65-
List<BugPathItem> bugPathItemList = new ArrayList<>();
66-
67-
for (NSObject bp : path) {
68-
NSDictionary bugPath = (NSDictionary) bp;
69-
70-
// We are only interested in bug events
71-
if (((NSString) bugPath.get("kind")).getContent().equals("event")) {
72-
String message = ((NSString) bugPath.get("message")).getContent();
73-
NSDictionary location = (NSDictionary) bugPath.get("location");
74-
Integer fileIndex = ((NSNumber) location.get("file")).intValue();
75-
Integer line = ((NSNumber) location.get("line")).intValue();
76-
Integer col = ((NSNumber) location.get("col")).intValue();
77-
String filePath = ((NSString) sourceFiles[fileIndex]).getContent();
78-
79-
BugPathItem bItem = new BugPathItem(new Position(line, col), new Position(line, col), message,
80-
filePath);
81-
bugPathItemList.add(bItem);
82-
}
83-
}
84-
85-
ProblemInfo pInfo = new ProblemInfo(ImmutableList.copyOf(bugPathItemList));
86-
87-
riList.add(new ReportInfo(checkerName, "testHash", Iterables.getLast(bugPathItemList).getFile(),
88-
description, 1, false, "testFile", Iterables.getLast(bugPathItemList), Optional.of(pInfo)));
89-
}
90-
91-
ImmutableList<ReportInfo> uriList = ImmutableList.copyOf(riList);
92-
sl.addReports(uriList);
93-
94-
} catch (ParserConfigurationException | ParseException | SAXException | PropertyListFormatException
95-
| IOException e) {
96-
// TODO Auto-generated catch block
97-
Logger.log(IStatus.ERROR, "Cannot Parse File :" + e.getMessage() + " in file: " + file.getName());
98-
//e.printStackTrace();
99-
}
100-
101-
return sl;
102-
}
103-
104-
// TODO javadoc!, and return parse results for storing them
105-
public SearchList processResultsForProject() {
106-
// TODO Get This
107-
String ws = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + "/.codechecker/"
108-
+ project.getName() + "/results";
109-
Logger.log(IStatus.INFO, "Parsing plists in :" + ws);
110-
File file = new File(ws);
111-
SearchList sl = new SearchList();
112-
for (File f : file.listFiles(new FilenameFilter() {
113-
114-
@Override
115-
public boolean accept(File dir, String name) {
116-
if (name.toLowerCase().endsWith(".plist"))
117-
return true;
118-
return false;
119-
}
120-
})) {
121-
//Logger.log(IStatus.INFO, "Parsing plist :" + f);
122-
parsePlist(f, sl);
123-
}
124-
return sl;
125-
}
126-
127-
/*@Override
128-
public void run() {
129-
processResultsForProject();
130-
}*/
36+
IProject project;
37+
38+
public PlistParser(IProject project) {
39+
this.project = project;
40+
}
41+
42+
/**
43+
* Parses exactly one .plist file.
44+
*
45+
* @param pathToFile
46+
* The file to be parsed.
47+
* @throws Exception
48+
*/
49+
public SearchList parsePlist(File file, SearchList sl) {
50+
List<ReportInfo> riList = new ArrayList<>();
51+
52+
NSDictionary dict;
53+
try {
54+
dict = (NSDictionary) PropertyListParser.parse(file);
55+
NSObject[] sourceFiles = ((NSArray) dict.objectForKey("files")).getArray();
56+
NSObject[] diagnostics = ((NSArray) dict.objectForKey("diagnostics")).getArray();
57+
58+
for (NSObject diagnostic : diagnostics) {
59+
NSDictionary diag = (NSDictionary) diagnostic;
60+
String checkerName = ((NSString) diag.get("check_name")).getContent();
61+
String description = ((NSString) diag.get("description")).getContent();
62+
63+
NSObject[] path = ((NSArray) diag.objectForKey("path")).getArray();
64+
65+
List<BugPathItem> bugPathItemList = new ArrayList<>();
66+
67+
for (NSObject bp : path) {
68+
NSDictionary bugPath = (NSDictionary) bp;
69+
70+
// We are only interested in bug events
71+
if (((NSString) bugPath.get("kind")).getContent().equals("event")) {
72+
String message = ((NSString) bugPath.get("message")).getContent();
73+
NSDictionary location = (NSDictionary) bugPath.get("location");
74+
Integer fileIndex = ((NSNumber) location.get("file")).intValue();
75+
Integer line = ((NSNumber) location.get("line")).intValue();
76+
Integer col = ((NSNumber) location.get("col")).intValue();
77+
String filePath = ((NSString) sourceFiles[fileIndex]).getContent();
78+
79+
BugPathItem bItem = new BugPathItem(new Position(line, col), new Position(line, col), message,
80+
filePath);
81+
bugPathItemList.add(bItem);
82+
}
83+
}
84+
85+
ProblemInfo pInfo = new ProblemInfo(ImmutableList.copyOf(bugPathItemList));
86+
87+
riList.add(new ReportInfo(checkerName, "testHash", Iterables.getLast(bugPathItemList).getFile(),
88+
description, 1, false, "testFile", Iterables.getLast(bugPathItemList), Optional.of(pInfo)));
89+
}
90+
91+
ImmutableList<ReportInfo> uriList = ImmutableList.copyOf(riList);
92+
sl.addReports(uriList);
93+
94+
} catch (ParserConfigurationException | ParseException | SAXException | PropertyListFormatException
95+
| IOException e) {
96+
// TODO Auto-generated catch block
97+
Logger.log(IStatus.ERROR, "Cannot Parse File :" + e.getMessage() + " in file: " + file.getName());
98+
//e.printStackTrace();
99+
}
100+
101+
return sl;
102+
}
103+
104+
// TODO javadoc!, and return parse results for storing them
105+
public SearchList processResultsForProject() {
106+
// TODO Get This
107+
String ws = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + "/.codechecker/"
108+
+ project.getName() + "/results";
109+
Logger.log(IStatus.INFO, "Parsing plists in :" + ws);
110+
File file = new File(ws);
111+
SearchList sl = new SearchList();
112+
if (file.exists()) {
113+
for (File f : file.listFiles(new FilenameFilter() {
114+
115+
@Override
116+
public boolean accept(File dir, String name) {
117+
if (name.toLowerCase().endsWith(".plist"))
118+
return true;
119+
return false;
120+
}
121+
})) {
122+
//Logger.log(IStatus.INFO, "Parsing plist :" + f);
123+
parsePlist(f, sl);
124+
}
125+
}
126+
return sl;
127+
}
128+
129+
/*@Override
130+
public void run() {
131+
processResultsForProject();
132+
}*/
131133
}

0 commit comments

Comments
 (0)