You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ken Cheung <ms...@gmail.com> on 2012/02/28 17:40:24 UTC

Inconsistency in AprEndpoint.java and JIoEndpoint.java

I observed some code clones in Tomcat and found inconsistent code. Could anyone explain why this is not a bug?

/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java

1048                    try {
1049                        Thread.sleep(1000);
1050                    } catch (InterruptedException e) {
1051                        // Ignore
1052                    }
1053                    long now = System.currentTimeMillis();
1054                    Iterator<SocketWrapper<Long>> sockets =
1055                        waitingRequests.iterator();
1056                    while (sockets.hasNext()) {
1057                        SocketWrapper<Long> socket = sockets.next();
1058                        if (socket.async) {
1059                            long access = socket.getLastAccess();
1060                            if (socket.getTimeout() > 0 &&
1061                                    (now-access)>socket.getTimeout()) {
1062                               
processSocketAsync(socket,SocketStatus.TIMEOUT);
1063                            }
1064                        }
1065                    }

/tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java

147                    try {
148                        Thread.sleep(1000);
149                    } catch (InterruptedException e) {
150                        // Ignore
151                    }
152                    long now = System.currentTimeMillis();
153                    Iterator<SocketWrapper<Socket>> sockets =
154                        waitingRequests.iterator();
155                    while (sockets.hasNext()) {
156                        SocketWrapper<Socket> socket = sockets.next();
157                        long access = socket.getLastAccess();
158                        if (socket.getTimeout() > 0 &&
159                                (now-access)>socket.getTimeout()) {
160                            processSocketAsync(socket,SocketStatus.TIMEOUT);
161                        }
162                    }
Quick description of the inconsistency
Two code snippets are very similar code, but as you see, in JIoEndpoint.java does not check "if (socket.async)" while AprEndpoint.java has the checker.

Re: Inconsistency in AprEndpoint.java and JIoEndpoint.java

Posted by Mark Thomas <ma...@apache.org>.
On 29/02/2012 04:51, Ken Cheung wrote:
> Because both of them are performing the same function. However, one
> of them (AprEndpoint.java:1057:1058) you typecast "SocketWrapper" to
> "Long" and check if "socket.async" is true while another one
> (JloEndpoint.java) you just typecast it to "Socket" and execute the
> same piece of codes. The checking of "socket.async" is missing here
> and therefore it could be a bug.

Oh dear. Where to start...?

Some things to consider:
- The code being different is no basis (on its own) for there being a
bug. The code snippets are supporting different Endpoint implementations
with different properties so it is entirely possible that the
implementations are different.
- Typecast? No. Not even close. You need to go and read up on generics
in Java.
- You assume that the check is missing in JIoEndpoint. Surely it is
equally possible that the check is unnecessary in AprEndpoint. You don't
appear to have considered that possibility.
- Before stating there is a bug, you need to understand what the code is
doing and have a credible explanation as to what might go wrong. You
don't have that. All you have is a statement that the code is different.

For the record, the code is correct and there is no bug but for the
benefit of the OP I'd like to see them work out why this is the case
rather than me spoon feeding them the explanation.

Mark

> 
> On 29 Feb, 2012, at 2:45 AM, Mark Thomas wrote:
> 
>> On 28/02/2012 16:40, Ken Cheung wrote:
>>> I observed some code clones in Tomcat and found inconsistent
>>> code. Could anyone explain why this is not a bug?
>> 
>> Yes.
>> 
>> Perhaps you'd like to explain your basis for assuming it is a bug.
>> 
>> Mark
>> 
>> ---------------------------------------------------------------------
>>
>> 
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
>
> 
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Inconsistency in AprEndpoint.java and JIoEndpoint.java

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ken Cheung [mailto:msrbugzilla@gmail.com] 
> Subject: Re: Inconsistency in AprEndpoint.java and JIoEndpoint.java

> you typecast "SocketWrapper" to "Long" and check if "socket.async"
> is true while another one (JloEndpoint.java) you just typecast it 
> to "Socket" and execute the same piece of codes.

If you think SocketWrapper<Long> is a type-cast, perhaps you need to do a bit more basic Java homework before telling people their code has bugs in it.  (Hint: SocketWrapper<> is, as its name and syntax suggest, a generic that adds behavior while hiding - that is to say, wrapping - any specified type.)

> The checking of "socket.async" is missing here and therefore it could 
> be a bug.

So could not checking if it's Tuesday, but that makes about as much sense.  (Hint: read the docs; check to see if the Jio connector can use asynchronous sockets.)

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistency in AprEndpoint.java and JIoEndpoint.java

Posted by Ken Cheung <ms...@gmail.com>.
Because both of them are performing the same function. However, one of them (AprEndpoint.java:1057:1058) you typecast "SocketWrapper" to "Long" and check if "socket.async" is true while another one (JloEndpoint.java) you just typecast it to "Socket" and execute the same piece of codes. The checking of "socket.async" is missing here and therefore it could be a bug.

On 29 Feb, 2012, at 2:45 AM, Mark Thomas wrote:

> On 28/02/2012 16:40, Ken Cheung wrote:
>> I observed some code clones in Tomcat and found inconsistent code.
>> Could anyone explain why this is not a bug?
> 
> Yes.
> 
> Perhaps you'd like to explain your basis for assuming it is a bug.
> 
> Mark
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Inconsistency in AprEndpoint.java and JIoEndpoint.java

Posted by Mark Thomas <ma...@apache.org>.
On 28/02/2012 16:40, Ken Cheung wrote:
> I observed some code clones in Tomcat and found inconsistent code.
> Could anyone explain why this is not a bug?

Yes.

Perhaps you'd like to explain your basis for assuming it is a bug.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org