Bug 541682 - Eclipse should refer to JDK version, when performing Save Action(s) "adding @Override annotation" OR having and ability to act differently on a per-file base.
Summary: Eclipse should refer to JDK version, when performing Save Action(s) "adding @...
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.10   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2018-11-29 03:15 EST by Pavel Bekkerman CLA
Modified: 2019-02-27 04:28 EST (History)
1 user (show)

See Also:


Attachments
JDK 1.6. is used in the project (13.62 KB, image/png)
2018-11-29 03:15 EST, Pavel Bekkerman CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pavel Bekkerman CLA 2018-11-29 03:15:53 EST
Created attachment 276758 [details]
JDK 1.6. is used in the project

I have a Save Action defined to put @Override wherever necessary.

Now, one of the files is java.sql.Driver implementer.
The Driver interface defines the following method:

public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException

When I save the implementer class file - it will automatically add @Override annotation to the implemented method name getParentLogger().

However, this method is only available starting JDK 1.7.
Hence, it will fail if I build with JDK 1.6.

Eclipse runs with JDK 1.8, but the Maven project is specified to use JDK 1.6. source-target. 

So, how come, the Save action still adds the @Override annotation?
(Which causes my build to fail.)
Comment 1 Dani Megert CLA 2018-11-29 05:53:52 EST
Please attach a test case/project.
Comment 2 Pavel Bekkerman CLA 2019-02-26 15:09:55 EST
This is the case:
```
import java.sql.Connection;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;

public class DummyDriver implements java.sql.Driver {

	@Override
	public boolean acceptsURL(String url) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Connection connect(String url, Properties info) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getMajorVersion() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getMinorVersion() {
		// TODO Auto-generated method stub
		return 0;
	}

	// jdbc 1.7 feature
	//@Override
	public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {

		throw new SQLFeatureNotSupportedException();
	}

	@Override
	public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean jdbcCompliant() {
		// TODO Auto-generated method stub
		return false;
	}
}
```
Comment 3 Pavel Bekkerman CLA 2019-02-26 15:12:39 EST
Now, I have to say, that, in the latest version of Eclipse (2019-01), it works as expected.

Once this is defined in .classpath, the @Override is not being added on Save:

	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>

Changing 1.6 to 1.8, the @Override is being added on Save:

	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>

So, I guess, it works properly.