Skip to content
Closed
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
14 changes: 8 additions & 6 deletions src/Xamarin.Android.Tools.Bytecode/ClassPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,15 @@ JavaDocletType GetDocletType (string path)
kind = JavaDocletType.Java8;

// Check to see if it's an api.xml formatted doc
string rawXML = null;
using (var reader = File.OpenText (path)) {
int len = reader.ReadBlock (buf, 0, buf.Length);
rawXML = new string (buf, 0, len);
if (File.Exists (path)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...Which means this proposed "fix" is Doomed To Fail™: if path must be a directory, then File.Exist(path) will always be false, meaning this code is dead code; it's not executable.

I think we need @Redth to chime in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the ClassParse task just passes in DocumentationPaths strings which usually is a directory, but could be a file, as the ApiXmlDocPaths is intended to be a path to an xml file.

I think this fix should work in this case since File.Exists will indeed skip over directories and this code is only hit for files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a quick test we could add with a file? Looking at the code, I think this part would fail if a file path came in:

using (var reader = File.OpenText (Path.Combine (path, "index.html")))
    reader.ReadBlock (buf, 0, buf.Length);

string rawXML = null;
using (var reader = File.OpenText (path)) {
int len = reader.ReadBlock (buf, 0, buf.Length);
rawXML = new string (buf, 0, len);
}
if (rawXML.Contains ("<api>") && rawXML.Contains ("<package"))
kind = JavaDocletType._ApiXml;
}
if (rawXML.Contains ("<api>") && rawXML.Contains ("<package"))
kind = JavaDocletType._ApiXml;

return kind;
}
Expand Down