anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: apache/camel-k-runtime
Issue: Can't get response from platform HTTP

Getting error whenever I try to read some binary content from a rest endpoint:

```
Error executing reactive work due to You must set the Content-Length header to be the total size of the message body BEFORE sending any data if you are not using HTTP chunked encoding.
```

I'm working on a fix

Changed files:
camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java

diff --git a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java
index 300fe915..bb448643 100644
--- a/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java
+++ b/camel-k-runtime-http/src/main/java/org/apache/camel/k/http/engine/RuntimePlatformHttpConsumer.java
@@ -200,6 +200,14 @@ public class RuntimePlatformHttpConsumer extends DefaultConsumer {
             ExchangeHelper.setFailureHandled(exchange);
         }
 
+        // set the content-length if it can be determined, or chunked encoding
+        final Integer length = determineContentLength(exchange, body);
+        if (length != null) {
+            response.putHeader("Content-Length", String.valueOf(length));
+        } else {
+            response.setChunked(true);
+        }
+
         // set the content type in the response.
         final String contentType = MessageHelper.getContentType(message);
         if (contentType != null) {
@@ -209,6 +217,15 @@ public class RuntimePlatformHttpConsumer extends DefaultConsumer {
         return body;
     }
 
+    static Integer determineContentLength(Exchange camelExchange, Object body) {
+        if (body instanceof byte[]) {
+            return ((byte[]) body).length;
+        } else if (body instanceof ByteBuffer) {
+            return ((ByteBuffer) body).remaining();
+        }
+        return null;
+    }
+
     /*
      * Copied from org.apache.camel.http.common.DefaultHttpBinding.determineResponseCode(Exchange, Object)
      * If DefaultHttpBinding.determineResponseCode(Exchange, Object) is moved to a module without the servlet-api
Repository: ably/ably-java
Issue: equals() for TokenDetails is broken

Following is how `equals` has been implemented for `TokenDetails`

```
 @Override
   public boolean equals(Object obj) {
            TokenDetails details = (TokenDetails)obj;
            return equalNullableStrings(this.token, details.token) &
                    equalNullableStrings(this.capability, details.capability) &
                    equalNullableStrings(this.clientId, details.clientId) &
                    (this.issued == details.issued) &
                    (this.expires == details.expires);
        }    
```
This implementation doesn't take into account when obj is null or not the type of token details.

**Expected**
Return false when obj is null or a different type

Spotted:
Flutter plugin Stream writer does this check when writing types to streams
```
protected void writeValue(@NonNull ByteArrayOutputStream stream, @Nullable Object value) {
    if (value == null || value.equals(null)) {
      stream.write(NULL);
```

Changed files:
lib/src/main/java/io/ably/lib/rest/Auth.java

diff --git a/lib/src/main/java/io/ably/lib/rest/Auth.java b/lib/src/main/java/io/ably/lib/rest/Auth.java
index e1c068b6..dc3fa9fc 100644
--- a/lib/src/main/java/io/ably/lib/rest/Auth.java
+++ b/lib/src/main/java/io/ably/lib/rest/Auth.java
@@ -6,6 +6,7 @@ import java.security.GeneralSecurityException;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Objects;
 
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
@@ -358,6 +359,8 @@ public class Auth {
          */
         @Override
         public boolean equals(Object obj) {
+            if (!(obj instanceof TokenDetails)) return false;
+
             TokenDetails details = (TokenDetails)obj;
             return equalNullableStrings(this.token, details.token) &
                     equalNullableStrings(this.capability, details.capability) &
@@ -366,7 +369,12 @@ public class Auth {
                     (this.expires == details.expires);
         }
 
-}
+        @Override
+        public int hashCode() {
+            return Objects.hash(token, capability, clientId, issued, expires);
+        }
+
+    }
 
     /**
      * Defines the properties of an Ably Token.
Repository: ably/ably-java
Issue: Provide an error code and error message for failed queued messages

The code below creates an empty error info when a pending message fails. It must also contain a convenient code and message (check spec and other SDKs)

https://github.com/ably/ably-java/blob/94ecb6fada26982aaa698f3291f150f344eb2cd4/lib/src/main/java/io/ably/lib/transport/ConnectionManager.java#L1800

Changed files:
lib/src/test/java/io/ably/lib/test/common/Helpers.java, lib/src/main/java/io/ably/lib/transport/ConnectionManager.java

diff --git a/lib/src/main/java/io/ably/lib/transport/ConnectionManager.java b/lib/src/main/java/io/ably/lib/transport/ConnectionManager.java
index 7dbe8b06..8891bd82 100644
--- a/lib/src/main/java/io/ably/lib/transport/ConnectionManager.java
+++ b/lib/src/main/java/io/ably/lib/transport/ConnectionManager.java
@@ -1682,7 +1682,7 @@ public class ConnectionManager implements ConnectListener {
             queuedMessages.clear();
 
             //also pending messages
-            pendingMessages.fail();
+            pendingMessages.fail(reason);
         }
     }
 
@@ -1795,9 +1795,11 @@ public class ConnectionManager implements ConnectListener {
         }
 
         //fail all pending queued emssages
-        synchronized void fail() {
+        synchronized void fail(ErrorInfo reason) {
             for (QueuedMessage queuedMessage: queue){
-                queuedMessage.listener.onError(new ErrorInfo());
+                if (queuedMessage.listener != null) {
+                    queuedMessage.listener.onError(reason);
+                }
             }
             queue.clear();
         }
diff --git a/lib/src/test/java/io/ably/lib/test/common/Helpers.java b/lib/src/test/java/io/ably/lib/test/common/Helpers.java
index 2dce9b10..55c4f3df 100644
--- a/lib/src/test/java/io/ably/lib/test/common/Helpers.java
+++ b/lib/src/test/java/io/ably/lib/test/common/Helpers.java
@@ -174,10 +174,13 @@ public class Helpers {
                     if (System.currentTimeMillis() > timeoutAt) {
                         break;
                     }
-                    
-                     wait(); 
+
+                     wait();
                 } catch(InterruptedException e) {}
             success = successCount >= count;
+            if (error != null) {
+                assertNotNull(error.message);
+            }
             return error;
         }
Repository: ably/ably-java
Issue: Connection manager switches to fallback hosts on close

https://github.com/ably/ably-java/blob/bbbcb4d1ee6e9bc7a8b98a2b4990259030e50725/lib/src/main/java/io/ably/lib/transport/ConnectionManager.java#L1393

When the transport becomes unavailable due to a number of reasons (including a clean close, or an abnormal close) the connection immediately jumps to a fallback host if the internet is up.

This is because the check for whether to use fallback includes checking for a `pendingConnect`, as well as the error reason being "server related". The `pendingConnect` is set when the connecting state is enacted, but not cleared apart from `checkFallback` if it's decided not to use a fallback.

This means any time the connection closes for a number of reasons, then the connection will immediately fallback and not resume.

Changed files:
lib/src/main/java/io/ably/lib/transport/ConnectionManager.java

diff --git a/lib/src/main/java/io/ably/lib/transport/ConnectionManager.java b/lib/src/main/java/io/ably/lib/transport/ConnectionManager.java
index 69f91299..cb442abe 100644
--- a/lib/src/main/java/io/ably/lib/transport/ConnectionManager.java
+++ b/lib/src/main/java/io/ably/lib/transport/ConnectionManager.java
@@ -265,6 +265,12 @@ public class ConnectionManager implements ConnectListener {
         void enactForChannel(StateIndication stateIndication, ConnectionStateChange change, Channel channel) {
             channel.setConnected(stateIndication.reattachOnResumeFailure);
         }
+
+        @Override
+        void enact(StateIndication stateIndication, ConnectionStateChange change) {
+            super.enact(stateIndication, change);
+            pendingConnect = null;
+        }
     }
 
     /**************************************************
Repository: ably/ably-java
Issue: Error code for message decoding failure

At the moment, https://github.com/ably/ably-java/blob/main/lib/src/main/java/io/ably/lib/types/MessageDecodeException.java uses code 91200 for decoding failure. This code is undocumented, and we should ideally be using 40013 instead.

Changed files:
lib/src/main/java/io/ably/lib/types/MessageDecodeException.java

diff --git a/lib/src/main/java/io/ably/lib/types/MessageDecodeException.java b/lib/src/main/java/io/ably/lib/types/MessageDecodeException.java
index 6d89d63a..3c404320 100644
--- a/lib/src/main/java/io/ably/lib/types/MessageDecodeException.java
+++ b/lib/src/main/java/io/ably/lib/types/MessageDecodeException.java
@@ -13,7 +13,7 @@ public class MessageDecodeException extends AblyException {
     public static MessageDecodeException fromDescription(String description) {
         return new MessageDecodeException(
             new Exception(description),
-            new ErrorInfo(description, 91200));
+            new ErrorInfo(description, 40013));
     }
 
     public static MessageDecodeException fromThrowableAndErrorInfo(Throwable e, ErrorInfo errorInfo) {
Repository: ably/ably-java
Issue: Error code for channel attachment timed out

In https://github.com/ably/ably-java/blob/c3f438a8b1992850f68a16f9e7517a5dc205727e/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java#L482 we use code 91200 for a timeout whilst attaching to the channel prior to suspension. This code is not documented anywhere.

The error code in question was removed somewhere around specification version 0.9, and should be removed in ably-java as well.

Changed files:
lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java, lib/src/main/java/io/ably/lib/realtime/ChannelBase.java

diff --git a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java
index fb28d966..453ee669 100644
--- a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java
+++ b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java
@@ -479,7 +479,7 @@ public abstract class ChannelBase extends EventEmitter<ChannelEvent, ChannelStat
                             }
                             attachTimer = null;
                             if(state == ChannelState.attaching) {
-                                setSuspended(new ErrorInfo(errorMessage, 91200), true);
+                                setSuspended(new ErrorInfo(errorMessage, 90007), true);
                                 reattachAfterTimeout();
                             }
                         }
diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java
index 46ddaaac..181dbc49 100644
--- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java
+++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java
@@ -1808,7 +1808,7 @@ public class RealtimeChannelTest extends ParameterizedTest {
 
             /* Should get to suspended soon because send() is blocked */
             ErrorInfo suspendReason = channelWaiter.waitFor(ChannelState.suspended);
-            assertEquals("Verify the suspended event contains the detach reason", 91200, suspendReason.code);
+            assertEquals("Verify the suspended event contains the detach reason", 90007, suspendReason.code);
 
             /* Unblock send(), and expect a transition to attached */
             mockTransport.allowSend();
Repository: ably/ably-java
Issue: Crypto.getRandomMessageId isn't working as intended

the value being generated by this method is returning the toString result of a char[], which probably is not the intended "random" value.



┆Issue is synchronized with this [Jira Bug](https://ably.atlassian.net/browse/SDK-659) by [Unito](https://www.unito.io)


Changed files:
lib/src/main/java/io/ably/lib/util/Crypto.java, lib/src/test/java/io/ably/lib/util/CryptoTest.java

diff --git a/lib/src/main/java/io/ably/lib/util/Crypto.java b/lib/src/main/java/io/ably/lib/util/Crypto.java
index b20915b0..56ea62fb 100644
--- a/lib/src/main/java/io/ably/lib/util/Crypto.java
+++ b/lib/src/main/java/io/ably/lib/util/Crypto.java
@@ -321,7 +321,7 @@ public class Crypto {
     public static String getRandomMessageId() {
         byte[] entropy = new byte[9];
         secureRandom.nextBytes(entropy);
-        return Base64Coder.encode(entropy).toString();
+        return Base64Coder.encodeToString(entropy);
     }
 
     /**
diff --git a/lib/src/test/java/io/ably/lib/util/CryptoTest.java b/lib/src/test/java/io/ably/lib/util/CryptoTest.java
index a9fec56d..f89541be 100644
--- a/lib/src/test/java/io/ably/lib/util/CryptoTest.java
+++ b/lib/src/test/java/io/ably/lib/util/CryptoTest.java
@@ -199,4 +199,10 @@ public class CryptoTest {
 
         return out.toByteArray();
     }
+
+    @Test
+    public void getRandomId() {
+        String randomId = Crypto.getRandomMessageId();
+        assertEquals(12, randomId.length());
+    }
 }