Jasig/uPortal — pull request #289 by apetro (2014-04-08 19:23:56+00:00)
Title: Drop JDK 1.6.  Require 1.7 or later.

As discussed on [uportal-user@](http://thread.gmane.org/gmane.comp.java.jasig.uportal/17047). JDK6 is EOL. Okay to start requiring (and taking advantage of) JDK7.

This changeset configures Ant to fail with a message when compiling under JDK 6, bumps the source and target versions of the Maven build to 1.7, and updates readme to reflect.

[One of four Travis-CI integration test runs of this code failed](http://thread.gmane.org/gmane.comp.java.jasig.uportal.devel/5635) with a `JpaPortletExecutionAggregationDaoTest` failure. I think this is a ghost in the machine rather than a consistently replicable error, but uPortal unit tests may need to continue to be improved to avoid intermittent false negatives.

Goodies in JDK 7 of which uPortal might begin to take advantage
=================================================

(Note that these are all real examples of uPortal source code that could be refactored to take advantage of Java 7 language features.)

Less [verbosity in declaring generics](http://radar.oreilly.com/2011/09/java7-features.html)
-------------------------------------------------

final PipelineEventReaderImpl cacheableEventReader =
new PipelineEventReaderImpl(xmlEventReader);

becomes

final PipelineEventReaderImpl cacheableEventReader =
new PipelineEventReaderImpl<>(xmlEventReader);

[Shorthand for resource management in try blocks](http://stackoverflow.com/questions/213958/new-features-in-java-7)
-------------------------------------------------

Statement statement = null;
ResultSet rs = null;
try {
statement = connection.createStatement();
rs = statement.executeQuery(sql);

while ( rs.next() ) {
sequences.add( rs.getString(1).toLowerCase().trim() );
}
}
finally {
if (rs!=null) rs.close();
if (statement!=null) statement.close();
}

becomes

try (Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql);) {

while ( rs.next() ) {
sequences.add( rs.getString(1).toLowerCase().trim() );
}
}

Catch clauses [catching multiple types of exceptions](http://stackoverflow.com/questions/213958/new-features-in-java-7)
-------------------------------------------------

try {
final ObjectName name = new ObjectName(nameString);
registerMbean(cacheStatistics, name);
}
catch (MalformedObjectNameException e) {
logger.warn("Failed to create ObjectName {} the corresponding CacheStatistics will not be registered with JMX", nameString, e);
}
catch (NullPointerException e) {
logger.warn("Failed to create ObjectName {} the corresponding CacheStatistics will not be registered with JMX", nameString, e);
}
catch (InstanceAlreadyExistsException e) {
logger.warn("ObjectName {} is already registered, the corresponding CacheStatistics will not be registered with JMX", nameString, e);
}
catch (MBeanRegistrationException e) {
logger.warn("Failed to register ObjectName {} the corresponding CacheStatistics will not be registered with JMX", nameString, e);
}
catch (NotCompliantMBeanException e) {
logger.warn("Failed to register ObjectName {} the corresponding CacheStatistics will not be registered with JMX", nameString, e);
}
}

becomes

try {
final ObjectName name = new ObjectName(nameString);
registerMbean(cacheStatistics, name);
}
catch (MalformedObjectNameException | NullPointerException | InstanceAlreadyExistsException
| MBeanRegistrationException | NotCompliantMBeanException e) {
logger.warn("Failed to create ObjectName {} the corresponding CacheStatistics will not be registered with JMX", nameString, e);
}

Other improvements
---------------------------

More subtle, but improvements to NIO and to threading may also be applicable.