[ https://issues.apache.org/jira/browse/NET-694?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary D. Gregory closed NET-694. ------------------------------- Resolution: Invalid No in reply in ~60 days, closing. > apache commons net 关于 DiscardUDPClient > -------------------------------------- > > Key: NET-694 > URL: https://issues.apache.org/jira/browse/NET-694 > Project: Commons Net > Issue Type: Improvement > Affects Versions: 3.6 > Reporter: wqd > Priority: Major > > There is "java.lang.IllegalArgumentException: illegal length" when i use > DiscardUDPClient to send. > > {code:java} > java.lang.IllegalArgumentException: illegal length > at java.net.DatagramPacket.setLength(DatagramPacket.java:378) > at > org.apache.commons.net.discard.DiscardUDPClient.send(DiscardUDPClient.java:68) > {code} > > See the source > "https://github.com/apache/commons-net/blob/master/src/main/java/org/apache/commons/net/discard/DiscardUDPClient.java". > {code:java} > public DiscardUDPClient() { > sendPacket = new DatagramPacket(new byte[0], 0); > } > public void send(final byte[] data, final int length, final InetAddress host, > final int port) > throws IOException > { > sendPacket.setData(data); > sendPacket.setLength(length); > sendPacket.setAddress(host); > sendPacket.setPort(port); > _socket_.send(sendPacket); > } > {code} > and "java.net.DatagramPacket". > {code:java} > public synchronized void setData(byte[] buf) { > if (buf == null) { > throw new NullPointerException("null packet buffer"); > } > this.buf = buf; > this.offset = 0; > this.length = buf.length; > this.bufLength = buf.length; > } > public synchronized void setLength(int length) { > if ((length + offset) > buf.length || length < 0 || > (length + offset) < 0) { > throw new IllegalArgumentException("illegal length"); > } > this.length = length; > this.bufLength = this.length; > } > {code} > I think in the case of multithreading, the "DiscardUDPClient.send" method is > not Atomicity. > I think that's why my problem came up. > > why not add synchronized for "DiscardUDPClient.send"? > > Forgive me for my nonstandard English > > > -- This message was sent by Atlassian Jira (v8.3.4#803005)