291 *
292 * @exception SocketException if the socket could not be opened,
293 * or the socket could not bind to the specified local port.
294 * @exception SecurityException if a security manager exists and its
295 * {@code checkListen} method doesn't allow the operation.
296 *
297 * @see SecurityManager#checkListen
298 * @since 1.1
299 */
300 public DatagramSocket(int port, InetAddress laddr) throws SocketException {
301 this(new InetSocketAddress(laddr, port));
302 }
303
304 private void checkOldImpl() {
305 if (impl == null)
306 return;
307 // DatagramSocketImpl.peekdata() is a protected method, therefore we need to use
308 // getDeclaredMethod, therefore we need permission to access the member
309 try {
310 AccessController.doPrivileged(
311 new PrivilegedExceptionAction<Void>() {
312 public Void run() throws NoSuchMethodException {
313 Class<?>[] cl = new Class<?>[1];
314 cl[0] = DatagramPacket.class;
315 impl.getClass().getDeclaredMethod("peekData", cl);
316 return null;
317 }
318 });
319 } catch (java.security.PrivilegedActionException e) {
320 oldImpl = true;
321 }
322 }
323
324 static Class<?> implClass = null;
325
326 void createImpl() throws SocketException {
327 if (impl == null) {
328 if (factory != null) {
329 impl = factory.createDatagramSocketImpl();
330 checkOldImpl();
331 } else {
|
291 *
292 * @exception SocketException if the socket could not be opened,
293 * or the socket could not bind to the specified local port.
294 * @exception SecurityException if a security manager exists and its
295 * {@code checkListen} method doesn't allow the operation.
296 *
297 * @see SecurityManager#checkListen
298 * @since 1.1
299 */
300 public DatagramSocket(int port, InetAddress laddr) throws SocketException {
301 this(new InetSocketAddress(laddr, port));
302 }
303
304 private void checkOldImpl() {
305 if (impl == null)
306 return;
307 // DatagramSocketImpl.peekdata() is a protected method, therefore we need to use
308 // getDeclaredMethod, therefore we need permission to access the member
309 try {
310 AccessController.doPrivileged(
311 new PrivilegedExceptionAction<>() {
312 public Void run() throws NoSuchMethodException {
313 Class<?>[] cl = new Class<?>[1];
314 cl[0] = DatagramPacket.class;
315 impl.getClass().getDeclaredMethod("peekData", cl);
316 return null;
317 }
318 });
319 } catch (java.security.PrivilegedActionException e) {
320 oldImpl = true;
321 }
322 }
323
324 static Class<?> implClass = null;
325
326 void createImpl() throws SocketException {
327 if (impl == null) {
328 if (factory != null) {
329 impl = factory.createDatagramSocketImpl();
330 checkOldImpl();
331 } else {
|