I’m getting some strange behaviour when I try to detach items from a Notes Document using a Java agent. Here’s the method that demonstrates the problem:
-----Code starts
private Vector detachAllFiles(Document doc) throws NotesException {
Vector<String> lofn0 = new Vector<String>(); // List of file names.
Vector<String> lofn1 = new Vector<String>(); // Another list of file
// names.
try {
Vector<Item> v = doc.getItems();
for (Item item : v) {
if (item.getType() == Item.ATTACHMENT) {
String fn = item.getValueString();
EmbeddedObject eo = doc.getAttachment(fn);
eo.extractFile(tempDirPath + "/" + fn);
lofn0.add(fn); // Add to the list of file names.
System.out.println("Added text string " + fn
+ " to list of file names in lofn0.\n");
System.out.println("Analysis of Vector lofn0 so far : - ");
System.out.println("There are " + lofn0.size()
+ " elements in the Vector lofn0");
for (String s : lofn0) {
System.out.println(s + ",\n"); // Show the element in
// the Java debug
// console
}
// This segment of code does essentially the same thing, but
// the data added to the Vector is a String literal.
lofn1.add("Backstock-Shopfloor-297-09022009.txt");
System.out.println("Added text string "
+ "Backstock-Shopfloor-297-09022009.txt"
+ " to list of file names in lofn1.\n");
System.out.println("Analysis of Vector lofn1 so far : - ");
System.out.println("There are " + lofn1.size()
+ " elements in the Vector lofn1");
for (String s : lofn1) {
System.out.println(s + ",\n");
}
}
}
} catch (Exception e) {
System.out.println("Error!");
System.out.println(e.getMessage());
}
return lofn0;
}
-----Code ends
… and the output is:
-----Output starts
Documents to process.1
Processing document
Temp dir path: C:\Program Files\IBM\Lotus\Notes\Data/Temp-SBON-7YLHYW
Added text string Backstock-Shopfloor-297-09022009.txtAnalysis of Vector lofn0 so far : -
There are 1 elements in the Vector lofn0
Backstock-Shopfloor-297-09022009.txtAdded text string NewProduct-297-09022009.txtThere are 2 elements in the Vector lofn0
Backstock-Shopfloor-297-09022009.txtAdded text string ResultFile-297-09022009.txtThere are 3 elements in the Vector lofn0
Backstock-Shopfloor-297-09022009.txt
-----Output ends
If I comment out the statement
-----Code starts
for (String s : lofn0) {
System.out.println(s + ",\n"); // Show the element in
// the Java debug // console
}
-----Code ends
then the output becomes:
-----Output starts
Documents to process.1
Processing document
Temp dir path: C:\Program Files\IBM\Lotus\Notes\Data/Temp-SBON-7YLJ4L
Added text string Backstock-Shopfloor-297-09022009.txtAnalysis of Vector lofn0 so far : -
There are 1 elements in the Vector lofn0
Added text string Backstock-Shopfloor-297-09022009.txt to list of file names in lofn1.
Analysis of Vector lofn1 so far : -
There are 1 elements in the Vector lofn1
Backstock-Shopfloor-297-09022009.txt,
Added text string NewProduct-297-09022009.txt
There are 2 elements in the Vector lofn0
Added text string Backstock-Shopfloor-297-09022009.txt to list of file names in lofn1.
Analysis of Vector lofn1 so far : -
There are 2 elements in the Vector lofn1
Backstock-Shopfloor-297-09022009.txt,
Backstock-Shopfloor-297-09022009.txt,
Added text string ResultFile-297-09022009.txt
There are 3 elements in the Vector lofn0
Added text string Backstock-Shopfloor-297-09022009.txt to list of file names in lofn1.
Analysis of Vector lofn1 so far : -
There are 3 elements in the Vector lofn1
Backstock-Shopfloor-297-09022009.txt,
Backstock-Shopfloor-297-09022009.txt,
Backstock-Shopfloor-297-09022009.txt,
File name: Backstock-Shopfloor-297-09022009.txt
-----Output ends
The point is, even if I’ve screwed up the code (a distinct possibility) the code should not just stop without feedback. This code is in a script library and does not return to the calling agent when it breaks. At least I should get some output from the catch block. But nothing seems to happen. Has anyone else got thoughts on this?