Skip to main content

Migrate to Java 6

org.openrewrite.java.migrate.UpgradeToJava6

This recipe will apply changes commonly needed when upgrading to Java 6. This recipe will also replace deprecated API with equivalents when there is a clear migration strategy.

Tags

Recipe source

GitHub: java-version-6.yml, Issue Tracker, Maven Central

This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above.

This recipe is available under the Moderne Source Available License.

Definition

Used by

This recipe is used as part of the following composite recipes:

Examples

Example 1

UpgradeToJava6Test#dataSource

Before
package com.test.withoutWrapperMethods;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

public class JRE6WrapperDataSource implements DataSource {

public Connection getConnection() throws SQLException {
// TODO Auto-generated method stub
return null;
}

public Connection getConnection(String username, String password)
throws SQLException {
// TODO Auto-generated method stub
return null;
}

public PrintWriter getLogWriter() throws SQLException {
// TODO Auto-generated method stub
return null;
}

public void setLogWriter(PrintWriter out) throws SQLException {
// TODO Auto-generated method stub

}

public void setLoginTimeout(int seconds) throws SQLException {
// TODO Auto-generated method stub

}

public int getLoginTimeout() throws SQLException {
// TODO Auto-generated method stub
return 0;
}

}
After
package com.test.withoutWrapperMethods;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

public class JRE6WrapperDataSource implements DataSource {

public Connection getConnection() throws SQLException {
// TODO Auto-generated method stub
return null;
}

public Connection getConnection(String username, String password)
throws SQLException {
// TODO Auto-generated method stub
return null;
}

public PrintWriter getLogWriter() throws SQLException {
// TODO Auto-generated method stub
return null;
}

public void setLogWriter(PrintWriter out) throws SQLException {
// TODO Auto-generated method stub

}

public void setLoginTimeout(int seconds) throws SQLException {
// TODO Auto-generated method stub

}

public int getLoginTimeout() throws SQLException {
// TODO Auto-generated method stub
return 0;
}

public boolean isWrapperFor(Class<?> iface) throws java.sql.SQLException {
// TODO Auto-generated method stub
return iface != null && iface.isAssignableFrom(this.getClass());
}

public <T> T unwrap(Class<T> iface) throws java.sql.SQLException {
// TODO Auto-generated method stub
try {
if (iface != null && iface.isAssignableFrom(this.getClass())) {
return (T) this;
}
throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation");
} catch (Exception e) {
throw new java.sql.SQLException(e);
}
}

}

Example 2

UpgradeToJava6Test#dataSource

Before
package com.test.withoutWrapperMethods;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

public class JRE6WrapperDataSource implements DataSource {

public Connection getConnection() throws SQLException {
// TODO Auto-generated method stub
return null;
}

public Connection getConnection(String username, String password)
throws SQLException {
// TODO Auto-generated method stub
return null;
}

public PrintWriter getLogWriter() throws SQLException {
// TODO Auto-generated method stub
return null;
}

public void setLogWriter(PrintWriter out) throws SQLException {
// TODO Auto-generated method stub

}

public void setLoginTimeout(int seconds) throws SQLException {
// TODO Auto-generated method stub

}

public int getLoginTimeout() throws SQLException {
// TODO Auto-generated method stub
return 0;
}

}
After
package com.test.withoutWrapperMethods;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

public class JRE6WrapperDataSource implements DataSource {

public Connection getConnection() throws SQLException {
// TODO Auto-generated method stub
return null;
}

public Connection getConnection(String username, String password)
throws SQLException {
// TODO Auto-generated method stub
return null;
}

public PrintWriter getLogWriter() throws SQLException {
// TODO Auto-generated method stub
return null;
}

public void setLogWriter(PrintWriter out) throws SQLException {
// TODO Auto-generated method stub

}

public void setLoginTimeout(int seconds) throws SQLException {
// TODO Auto-generated method stub

}

public int getLoginTimeout() throws SQLException {
// TODO Auto-generated method stub
return 0;
}

public boolean isWrapperFor(Class<?> iface) throws java.sql.SQLException {
// TODO Auto-generated method stub
return iface != null && iface.isAssignableFrom(this.getClass());
}

public <T> T unwrap(Class<T> iface) throws java.sql.SQLException {
// TODO Auto-generated method stub
try {
if (iface != null && iface.isAssignableFrom(this.getClass())) {
return (T) this;
}
throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation");
} catch (Exception e) {
throw new java.sql.SQLException(e);
}
}

}

Usage

This recipe has no required configuration options. Users of Moderne can run it via the Moderne CLI.

You will need to have configured the Moderne CLI on your machine before you can run the following command.

shell
mod run . --recipe UpgradeToJava6

If the recipe is not available locally, then you can install it using:

mod config recipes jar install org.openrewrite.recipe:rewrite-migrate-java:3.36.0

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Data Tables

Maven metadata failures

org.openrewrite.maven.table.MavenMetadataFailures

Attempts to resolve maven metadata that failed.

Column NameDescription
Group idThe groupId of the artifact for which the metadata download failed.
Artifact idThe artifactId of the artifact for which the metadata download failed.
VersionThe version of the artifact for which the metadata download failed.
Maven repositoryThe URL of the Maven repository that the metadata download failed on.
SnapshotsDoes the repository support snapshots.
ReleasesDoes the repository support releases.
FailureThe reason the metadata download failed.