Bug 196169 - With Ant build, java class file is generated even the source has syntax errors
Summary: With Ant build, java class file is generated even the source has syntax errors
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-11 11:12 EDT by Jianhua Gong CLA
Modified: 2007-12-20 06:54 EST (History)
2 users (show)

See Also:


Attachments
Test source file, build.xml, .classpath and .project (1.27 KB, application/x-zip-compressed)
2007-07-11 11:15 EDT, Jianhua Gong CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jianhua Gong CLA 2007-07-11 11:12:51 EDT
I'm running the following test build.xml to compile a single java file.  Eclipse creates a class file for me even the source has syntax erros.

Following are steps to reproduce:
0. Suppose current time is 9:00AM and the source file is correct.

1. Use menu Run->External Tools to run the target "fast-build" in build.xml

2. Eclipse generates a class file correctly with timestamp 9:01AM

3. Wait a minute and comment out the constant definition at line 2 in the source.  The file is saved at 9:02AM.

4. Use menu Run->External Tools to run the target "fast-build" again, Eclipse creates a new class file with timestamp 9:02AM.  The compiler detects the source is newer than the old class file.  So it tries to recompile.  It should report a syntax error.  However it somehow generates a new class file and displays "build successful" in the Console window.  Note it does flag the error in Problem window.  But this is not enough.  Console window should show the error too.

5. Now delete the new class file with timestamp 9:02AM from file system and run the "fast-build" target again.  This time Eclipse shows the syntax error in Console window.

Attached are source file, build.xml, .classpath and .project.

*****************************************
Source file:
public class TestEclipseCompiler {
    public static final String JNDI_NAME = "MyJNDIName";
    public static void main(String args[]) {
        System.out.println(JNDI_NAME);
    }
}

*****************************************
Build.xml:

<project name="Test Eclipse Compiler" default="fast-build" basedir=".">
	<property name="src" location="${basedir}"/>
	<property name="destclass" location="${basedir}/class"/>
	<property name="destjar" location="${basedir}/jar"/>

    <target name="init" description="Initialize the build">
        <tstamp/>
        <mkdir dir="${destclass}"/>
        <mkdir dir="${destjar}"/>
    </target>

    <target name="clean" depends="init" description="Clean the build">
        <delete includeemptydirs="true">
			<fileset dir="${destclass}" includes="**/*"/>
		</delete>
        <delete includeemptydirs="true">
			<fileset dir="${destjar}" includes="**/*"/>
		</delete>                
    </target>
    
    <target name="fast-build" depends="init" description="Build the project">
        <javac 
		    srcdir="${src}" 
		    destdir="${destclass}" 
			source="1.4"
        />
        <jar jarfile="${destjar}/TestEclipseCompiler.jar" 
	    	basedir="${destclass}" 
	    	>
		</jar> 
    </target>
    
    <target name="build-all" depends="clean, fast-build" description="Build the project completetly">
    
    </target>
</project>

*****************************************
.classpath:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path=""/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
	<classpathentry kind="output" path="class"/>
</classpath>

*****************************************
.project:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>TestEclipseCompiler</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jdt.core.javanature</nature>
	</natures>
</projectDescription>
Comment 1 Jianhua Gong CLA 2007-07-11 11:15:31 EDT
Created attachment 73553 [details]
Test source file, build.xml, .classpath and .project
Comment 2 Olivier Thomann CLA 2007-07-11 11:40:23 EDT
Move it back to JDT/Core for investigation.
Comment 3 Olivier Thomann CLA 2007-07-11 11:41:52 EDT
Did you disable the java builder ?
Comment 4 Olivier Thomann CLA 2007-07-11 14:37:27 EDT
Disabling the auto-build doesn't disable the java builder.
Select the project.
Open the properties
Go to Builders entry and uncheck the java builder.
Let me know if this fixes it.
Comment 5 Jianhua Gong CLA 2007-07-12 09:42:38 EDT
It worked after disabling the java builder.  Thanks, Olivier!
Comment 6 Olivier Thomann CLA 2007-07-12 09:47:32 EDT
Closing as INVALID.
The .class files were generated by the java builder and not by the ant adapter.
Comment 7 Frederic Fusier CLA 2007-12-20 06:54:21 EST
Verified by reporter