Better exception message to tell the user why it is not supported

This commit is contained in:
Norman Maurer 2014-01-30 07:00:53 +01:00
parent cd5103feb7
commit f7f808c7e0

View File

@ -83,9 +83,7 @@ public final class NioDatagramChannel
return newSocket();
}
if (PlatformDependent.javaVersion() < 7) {
throw new UnsupportedOperationException();
}
checkJavaVersion();
try {
return DatagramChannel.open(ProtocolFamilyConverter.convert(ipFamily));
@ -94,6 +92,12 @@ public final class NioDatagramChannel
}
}
private static void checkJavaVersion() {
if (PlatformDependent.javaVersion() < 7) {
throw new UnsupportedOperationException("Only supported on java 7+.");
}
}
/**
* Create a new instance which will use the Operation Systems default {@link InternetProtocolFamily}.
*/
@ -350,7 +354,9 @@ public final class NioDatagramChannel
public ChannelFuture joinGroup(
InetAddress multicastAddress, NetworkInterface networkInterface,
InetAddress source, ChannelPromise promise) {
if (PlatformDependent.javaVersion() >= 7) {
checkJavaVersion();
if (multicastAddress == null) {
throw new NullPointerException("multicastAddress");
}
@ -380,9 +386,7 @@ public final class NioDatagramChannel
} catch (Throwable e) {
promise.setFailure(e);
}
} else {
throw new UnsupportedOperationException();
}
return promise;
}
@ -425,9 +429,8 @@ public final class NioDatagramChannel
public ChannelFuture leaveGroup(
InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source,
ChannelPromise promise) {
if (PlatformDependent.javaVersion() < 7) {
throw new UnsupportedOperationException();
}
checkJavaVersion();
if (multicastAddress == null) {
throw new NullPointerException("multicastAddress");
}
@ -479,9 +482,8 @@ public final class NioDatagramChannel
public ChannelFuture block(
InetAddress multicastAddress, NetworkInterface networkInterface,
InetAddress sourceToBlock, ChannelPromise promise) {
if (PlatformDependent.javaVersion() < 7) {
throw new UnsupportedOperationException();
} else {
checkJavaVersion();
if (multicastAddress == null) {
throw new NullPointerException("multicastAddress");
}
@ -509,7 +511,6 @@ public final class NioDatagramChannel
promise.setSuccess();
return promise;
}
}
/**
* Block the given sourceToBlock address for the given multicastAddress