diff --git a/org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaProject.scala b/org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaProject.scala index 883791b69f..37ceb45c90 100644 --- a/org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaProject.scala +++ b/org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaProject.scala @@ -142,8 +142,6 @@ class ScalaProject(val underlying: IProject) extends HasLogger { def externalDepends = underlying.getReferencedProjects lazy val javaProject = { - if (!underlying.exists()) - underlying.create(null) JavaCore.create(underlying) } @@ -364,10 +362,15 @@ class ScalaProject(val underlying: IProject) extends HasLogger { } def initialize(settings: Settings, filter: Settings#Setting => Boolean) = { - val env = new NameEnvironment(javaProject) - - for ((src, dst) <- sourceOutputFolders(env)) - settings.outputDirs.add(EclipseResource(src), EclipseResource(dst)) + + // if the workspace project doesn't exist, it is a virtual project used by Eclipse. + // As such the source folders don't exist. + if (underlying.exists()) { + val env = new NameEnvironment(javaProject) + + for ((src, dst) <- sourceOutputFolders(env)) + settings.outputDirs.add(EclipseResource(src), EclipseResource(dst)) + } // TODO Per-file encodings val sfs = sourceFolders diff --git a/org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaCompilationUnit.scala b/org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaCompilationUnit.scala index c30a92d14b..028a985c3e 100644 --- a/org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaCompilationUnit.scala +++ b/org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaCompilationUnit.scala @@ -34,6 +34,7 @@ import org.eclipse.jdt.core.IParent import org.eclipse.jdt.internal.core.JavaElement import org.eclipse.jdt.internal.core.SourceRefElement import scala.tools.eclipse.util.HasLogger +import org.eclipse.jdt.core.compiler.CharOperation trait ScalaCompilationUnit extends Openable with env.ICompilationUnit with ScalaElement with IScalaCompilationUnit with IBufferChangedListener with HasLogger { val project = ScalaPlugin.plugin.getScalaProject(getJavaProject.getProject) @@ -58,7 +59,9 @@ trait ScalaCompilationUnit extends Openable with env.ICompilationUnit with Scala } def createSourceFile : BatchSourceFile = { - new BatchSourceFile(file, getContents) + // call getContent() only when the underlying resource exists, otherwise + // it logs an exception + new BatchSourceFile(file, if (getResource.exists) getContents else CharOperation.NO_CHAR) } def getProblemRequestor : IProblemRequestor = null