Community
Participate
Working Groups
Since AST supports stand-alone environments, it seems puzzling that JavaCore.getDefaultOptions() throws an exception when there is no workspace. The actual culprit, as indicated by the stack trace below, is ResourcesPlugin.getWorkspace(). It is interesting to notice that the null check on JavaCore.getEncoding() doesn't do much (so a possible way of avoiding the exception is to change it to a try/catch). Exception in thread "main" java.lang.IllegalStateException: Workspace is closed. at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:326) at org.eclipse.jdt.core.JavaCore.getEncoding(JavaCore.java:2893) at org.eclipse.jdt.internal.core.JavaModelManager.getDefaultOptions(JavaModelManager.java:1685) at org.eclipse.jdt.core.JavaCore.getDefaultOptions(JavaCore.java:2880) ...
Given that ResourcesPlugin.getWorkspace is like this: public static IWorkspace getWorkspace() { if (workspace == null) throw new IllegalStateException(Messages.resources_workspaceClosed); return workspace; } It seems impossible for the null guard in this code to ever have the intended consequence of returning the default encoding instead of the workspace charset. public static String getEncoding() { // Verify that workspace is not shutting down (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=60687) IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (workspace != null) { try { return workspace.getRoot().getDefaultCharset(); } catch (CoreException e) { // fails silently and return plugin global encoding if core exception occurs } } return ResourcesPlugin.getEncoding(); }
Created attachment 82185 [details] Proposed patch
Released for 3.4M4 in HEAD stream.
Thanks!
Verified for 3.4 M4 using build I20071210-1800