Community
Participate
Working Groups
Created attachment 88053 [details] Suggestion for the fix Pls see bugzilla https://bugs.eclipse.org/bugs/show_bug.cgi?id=208807 as this new problem is related to that one. The changes made to fix that bugzilla avoid this line in the JavaCore.getEncoding() method to throw an exception: ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset(); The problem now is that the very last line, return ResourcesPlugin.getEncoding(); fails with a NPE, because ResourcePlugin.getPlugin() returns null when there is no workspace. I am attaching a patch with a fix that solves the problems on the scenario I am working now. As you can see, I am returning the system's file encoding, which is what is done by ResourcesPlugin.getEncoding().
Created attachment 88126 [details] Proposed patch The proposed fix takes advantage of the fact that ResourcePlugin.getWorkspace() throws an IllegalStateException when there's no workspace. Then, bug 60687 should also be definitely fixed as well... No test case added as JDT/Core tests always have a workspace. To validate the fix, I run following simple class as a JUnit Test (no plug-in): import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.tests.junit.extension.TestCase; public class TestEncoding extends TestCase { public TestEncoding(String name) { super(name); } public void test01() { assertEquals("Cp1252", JavaCore.getEncoding()); } }
Released for 3.4M5 in HEAD stream.
Verified for 34M5 using I20080204-0010 build. However, I would suggest that a test be added to our test projects.
(In reply to comment #3) > Verified for 34M5 using I20080204-0010 build. > > However, I would suggest that a test be added to our test projects. > Verifying that is definitely not possible as all Eclipse JUnit tests are run as 'JUnit Plug-in tests' and so ResourcePlugin.getWorkspace() will never return a null value or throw a CoreException (even for our compiler tests...). As this condition is necessary to reproduce the bug, we cannot add any regression test to verify this new correct behavior...