Fix an occasional NPE that could happen if the ProjectBuiltQuery.getStatus() was called on an un opened project.
1.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/models/FacesModelSet.java Wed Apr 11 21:54:59 2007 +0000
1.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/models/FacesModelSet.java Wed Apr 11 22:23:50 2007 +0000
1.3 @@ -99,6 +99,8 @@
1.4
1.5 FacesConfigModel facesConfigModel;
1.6
1.7 + private ProjectBuiltQuery.Status projectBuiltQueryStatus;
1.8 +
1.9 // Listener to monitor file system changes. This is used to keep the folder structure under the
1.10 // document root folder synchronized with the folder structure under the page bean root folder.
1.11 private static class FolderStructureFileChangeListener implements FileChangeListener {
1.12 @@ -341,12 +343,16 @@
1.13 // save the files to prevent them being open unsaved
1.14 saveAll();
1.15
1.16 - final ProjectBuiltQuery.Status status = ProjectBuiltQuery.getStatus(project);
1.17 - status.addChangeListener(new ChangeListener() {
1.18 - public void stateChanged(ChangeEvent e) {
1.19 - if (status.isBuilt()) {
1.20 - classPathChanged();
1.21 - }
1.22 + projectBuiltQueryStatus = ProjectBuiltQuery.getStatus(project);
1.23 + projectBuiltQueryStatus.addChangeListener(new ChangeListener() {
1.24 + public void stateChanged(ChangeEvent changeEvent) {
1.25 + try {
1.26 + if (projectBuiltQueryStatus.isBuilt()) {
1.27 + classPathChanged();
1.28 + }
1.29 + } catch (IllegalStateException ise) {
1.30 + ErrorManager.getDefault().notify(ise);
1.31 + }
1.32 }
1.33 });
1.34 }
1.35 @@ -356,6 +362,7 @@
1.36 */
1.37 public void destroy() {
1.38 facesContainer.destroy();
1.39 + projectBuiltQueryStatus = null;
1.40 super.destroy();
1.41 }
1.42
2.1 --- a/visualweb.insync/src/org/netbeans/modules/visualweb/insync/models/ProjectBuiltQuery.java Wed Apr 11 21:54:59 2007 +0000
2.2 +++ b/visualweb.insync/src/org/netbeans/modules/visualweb/insync/models/ProjectBuiltQuery.java Wed Apr 11 22:23:50 2007 +0000
2.3 @@ -71,8 +71,6 @@
2.4 *
2.5 * This will throw a <code>NullPointerException</code> if a <code>null</code>
2.6 * <code>project</code> is passed in.
2.7 - * This will throw a <code>IllegalStateException</code> if the
2.8 - * <code>project</code> is not open.
2.9 * This will throw a <code>IllegalArgumentException</code> if the
2.10 * <code>project</code> does not have any <code>org.netbeans.api.project.SourceGroup<code>s.
2.11 *
2.12 @@ -174,10 +172,6 @@
2.13 throw new NullPointerException();
2.14 }
2.15
2.16 - if (!isProjectOpen()) {
2.17 - throw new IllegalStateException(NbBundle.getMessage(ProjectBuiltQuery.class, "ERROR_ProjectIsNotOpen"));
2.18 - }
2.19 -
2.20 Sources sources = project.getLookup().lookup(Sources.class);
2.21 if (sources == null) {
2.22 throw new IllegalArgumentException(NbBundle.getMessage(ProjectBuiltQuery.class, "ERROR_ProjectHasNoSources"));
2.23 @@ -226,7 +220,7 @@
2.24 }
2.25
2.26 public boolean isBuilt() {
2.27 - if (!isProjectOpen()) {
2.28 + if (!checkProjectOpen()) {
2.29 throw new IllegalStateException(NbBundle.getMessage(ProjectBuiltQuery.class, "ERROR_ProjectIsNotOpen"));
2.30 }
2.31 return built;
2.32 @@ -344,7 +338,11 @@
2.33 if (project == null) {
2.34 return false;
2.35 }
2.36 - boolean open = Arrays.asList(OpenProjects.getDefault().getOpenProjects()).contains(project);
2.37 + return Arrays.asList(OpenProjects.getDefault().getOpenProjects()).contains(project);
2.38 + }
2.39 +
2.40 + private boolean checkProjectOpen() {
2.41 + boolean open = isProjectOpen();
2.42 if (!open) {
2.43 dispose();
2.44 }
2.45 @@ -353,7 +351,9 @@
2.46
2.47 private void dispose() {
2.48 try {
2.49 - project.getProjectDirectory().getFileSystem().removeFileChangeListener(this);
2.50 + if (project != null) {
2.51 + project.getProjectDirectory().getFileSystem().removeFileChangeListener(this);
2.52 + }
2.53 } catch (FileStateInvalidException e) {
2.54 Exceptions.printStackTrace(e);
2.55 }