Commit 783ebf23 authored by Michael Ritter's avatar Michael Ritter
Browse files

#6 Avoid possible NPE

parent 3ab75c9a
...@@ -120,22 +120,16 @@ public class BrowseServlet extends EntityManagerServlet { ...@@ -120,22 +120,16 @@ public class BrowseServlet extends EntityManagerServlet {
request.setAttribute("collection", c); request.setAttribute("collection", c);
session.setAttribute(SESSION_FILE, session.setAttribute(SESSION_FILE,
loadFileBean(dt.getDirectoryNode(itemId), em,c)); loadFileBean(dt.getDirectoryNode(itemId), em,c));
if ( dt.getDirectoryNode(itemId).isDirectory() ) { if (dt.getDirectoryNode(itemId) != null && dt.getDirectoryNode(itemId).isDirectory()) {
dt.toggleItem(itemId); dt.toggleItem(itemId);
} }
// else
// {
// session.setAttribute(SESSION_FILE,
// loadFileBean(dt.getDirectoryNode(itemId)));
// }
} }
request.setAttribute(PAGE_ISAUDITING, isRunning); request.setAttribute(PAGE_ISAUDITING, isRunning);
RequestDispatcher dispatcher = request.getRequestDispatcher("browse.jsp"); RequestDispatcher dispatcher = request.getRequestDispatcher("browse.jsp");
dispatcher.forward(request, response); dispatcher.forward(request, response);
} }
private FileBean loadFileBean( DirectoryNode node, EntityManager em, Collection c ) { private FileBean loadFileBean(DirectoryNode node, EntityManager em, Collection c) {
// avoid possible null references below // avoid possible null references below
if (node == null) { if (node == null) {
return null; return null;
...@@ -144,20 +138,20 @@ public class BrowseServlet extends EntityManagerServlet { ...@@ -144,20 +138,20 @@ public class BrowseServlet extends EntityManagerServlet {
FileBean retBean = new FileBean(); FileBean retBean = new FileBean();
try { try {
MonitoredItem master = em.getReference(MonitoredItem.class, MonitoredItem master = em.getReference(MonitoredItem.class, node.getId());
node.getId());
retBean.root = master; retBean.root = master;
retBean.name = node.getName(); retBean.name = node.getName();
if (master.getToken() != null) { if (master.getToken() != null) {
// TokenResponse resp = (TokenResponse)master.getToken().getToken(); MessageDigest digest = MessageDigest.getInstance(
MessageDigest digest = MessageDigest.getInstance(master.getToken().getProofAlgorithm()); master.getToken().getProofAlgorithm());
ProofValidator pv = new ProofValidator(); ProofValidator pv = new ProofValidator();
Proof proof = TokenUtil.extractProof(master.getToken()); Proof proof = TokenUtil.extractProof(master.getToken());
String fileDigest = master.getFileDigest(); String fileDigest = master.getFileDigest();
if ( fileDigest != null ){ if (fileDigest != null){
byte[] root = pv.rootHash(digest, proof, HashValue.asBytes(master.getFileDigest())); byte[] root = pv.rootHash(digest, proof,
HashValue.asBytes(master.getFileDigest()));
retBean.itemProof = HashValue.asHexString(root); retBean.itemProof = HashValue.asHexString(root);
}else { }else {
retBean.itemProof = null; retBean.itemProof = null;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment