Skip to content

Commit

Permalink
7113208: Incorrect javadoc on java.net.DatagramPacket.setLength()
Browse files Browse the repository at this point in the history
Reviewed-by: dfuchs
  • Loading branch information
jaikiran committed Sep 3, 2022
1 parent ac05bc8 commit a366e82
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/java.base/share/classes/java/net/DatagramPacket.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,6 +25,10 @@

package java.net;

import java.util.Objects;

import jdk.internal.util.Preconditions;

/**
* This class represents a datagram packet.
* <p>
Expand Down Expand Up @@ -285,12 +289,9 @@ public synchronized int getLength() {
* @since 1.2
*/
public synchronized void setData(byte[] buf, int offset, int length) {
/* this will check to see if buf is null */
if (length < 0 || offset < 0 ||
(length + offset) < 0 ||
((length + offset) > buf.length)) {
throw new IllegalArgumentException("illegal length or offset");
}
Objects.requireNonNull(buf);
Preconditions.checkFromIndexSize(offset, length, buf.length,
Preconditions.outOfBoundsExceptionFormatter(IllegalArgumentException::new));
this.buf = buf;
this.length = length;
this.bufLength = length;
Expand Down Expand Up @@ -394,8 +395,9 @@ public synchronized void setData(byte[] buf) {
* Set the length for this packet. The length of the packet is
* the number of bytes from the packet's data buffer that will be
* sent, or the number of bytes of the packet's data buffer that
* will be used for receiving data. The length must be lesser or
* equal to the offset plus the length of the packet's buffer.
* will be used for receiving data. The {@code length} plus the
* {@link #getOffset() offset} must be lesser or equal to the
* length of the packet's data buffer.
*
* @param length the length to set for this packet.
*
Expand All @@ -409,10 +411,8 @@ public synchronized void setData(byte[] buf) {
* @since 1.1
*/
public synchronized void setLength(int length) {
if ((length + offset) > buf.length || length < 0 ||
(length + offset) < 0) {
throw new IllegalArgumentException("illegal length");
}
Preconditions.checkFromIndexSize(offset, length, buf.length,
Preconditions.outOfBoundsExceptionFormatter(IllegalArgumentException::new));
this.length = length;
this.bufLength = this.length;
}
Expand Down

1 comment on commit a366e82

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.