From 37e51812d65fe4e0fa3556c4c3e4a28568c9cd41 Mon Sep 17 00:00:00 2001 From: hns Date: Wed, 20 Jul 2005 11:42:16 +0000 Subject: [PATCH] Should fix bug 434 * Synchronize all methods that call/rely on update(). * Make sure repositories and resources are not null after update() has been called. --- src/helma/framework/repository/AbstractRepository.java | 8 ++++---- src/helma/framework/repository/FileRepository.java | 7 +++++-- src/helma/framework/repository/ZipRepository.java | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/helma/framework/repository/AbstractRepository.java b/src/helma/framework/repository/AbstractRepository.java index e2a4d610..497c11f2 100644 --- a/src/helma/framework/repository/AbstractRepository.java +++ b/src/helma/framework/repository/AbstractRepository.java @@ -97,7 +97,7 @@ public abstract class AbstractRepository implements Repository { * If the name can't be resolved to a resource, a resource object is returned * for which {@link Resource exists()} returns false. */ - public Resource getResource(String name) { + public synchronized Resource getResource(String name) { update(); Resource res = (Resource) resources.get(name); @@ -112,7 +112,7 @@ public abstract class AbstractRepository implements Repository { /** * Get an iterator over the resources contained in this repository. */ - public Iterator getResources() { + public synchronized Iterator getResources() { update(); return resources.values().iterator(); @@ -121,7 +121,7 @@ public abstract class AbstractRepository implements Repository { /** * Get an iterator over the sub-repositories contained in this repository. */ - public Repository[] getRepositories() { + public synchronized Repository[] getRepositories() { update(); return repositories; @@ -138,7 +138,7 @@ public abstract class AbstractRepository implements Repository { * Get a deep list of this repository's resources, including all resources * contained in sub-reposotories. */ - public List getAllResources() throws IOException { + public synchronized List getAllResources() throws IOException { update(); ArrayList allResources = new ArrayList(); diff --git a/src/helma/framework/repository/FileRepository.java b/src/helma/framework/repository/FileRepository.java index fcfb4272..619797a4 100644 --- a/src/helma/framework/repository/FileRepository.java +++ b/src/helma/framework/repository/FileRepository.java @@ -115,7 +115,7 @@ public class FileRepository extends AbstractRepository { return directory.lastModified(); } - public long getChecksum() throws IOException { + public synchronized long getChecksum() throws IOException { // delay checksum check if already checked recently if (System.currentTimeMillis() > lastChecksumTime + cacheTime) { @@ -141,8 +141,11 @@ public class FileRepository extends AbstractRepository { public synchronized void update() { if (!directory.exists()) { repositories = new Repository[0]; - if (resources != null) + if (resources != null) { + resources = new HashMap(); + } else { resources.clear(); + } lastModified = 0; return; } diff --git a/src/helma/framework/repository/ZipRepository.java b/src/helma/framework/repository/ZipRepository.java index d5da9ed3..afa8a9ba 100644 --- a/src/helma/framework/repository/ZipRepository.java +++ b/src/helma/framework/repository/ZipRepository.java @@ -95,7 +95,9 @@ public final class ZipRepository extends AbstractRepository { } public synchronized void update() { - if (file.lastModified() != lastModified) { + if (file.lastModified() != lastModified || + repositories == null || + resources == null) { lastModified = file.lastModified(); ZipFile zipfile = null;