Skip to content

Commit bd06958

Browse files
author
Nick Johnson
committed
Fixes two broken tests; now that the username and password aren't simple
(and immutable) strings, a .clone() operation needs to specifically return a clone of the CredentialsProvider that can be modified with setUsername/setPassword without affecting the original instance.
1 parent fdda435 commit bd06958

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/main/java/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,9 @@ protected AddressResolver createAddressResolver(List<Address> addresses) {
10801080

10811081
@Override public ConnectionFactory clone(){
10821082
try {
1083-
return (ConnectionFactory)super.clone();
1083+
ConnectionFactory clone = (ConnectionFactory)super.clone();
1084+
clone.credentialsProv = (CredentialsProvider)clone.credentialsProv.clone();
1085+
return clone;
10841086
} catch (CloneNotSupportedException e) {
10851087
throw new Error(e);
10861088
}

src/main/java/com/rabbitmq/client/impl/AbstractCredentialsProvider.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,14 @@ public void setUsername(String username) {
3535
public void setPassword(String password) {
3636
throw new UnsupportedOperationException();
3737
}
38+
39+
/**
40+
* Default clone() behavior is to call Object's clone() method. If you need more custom
41+
* behavior, override clone().
42+
*/
43+
@Override
44+
public Object clone() throws CloneNotSupportedException {
45+
return super.clone();
46+
}
3847

3948
}

src/main/java/com/rabbitmq/client/impl/CredentialsProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
* Provider interface for establishing credentials for connecting to the broker. Especially useful
55
* for situations where credentials might change before a recovery takes place or where it is
66
* convenient to plug in an outside custom implementation.
7+
*
8+
* @see com.rabbitmq.client.impl.AbstractCredentialsProvider
79
*/
8-
public interface CredentialsProvider {
10+
public interface CredentialsProvider extends Cloneable {
911

1012
String getUsername();
1113

@@ -15,4 +17,6 @@ public interface CredentialsProvider {
1517

1618
void setPassword(String password);
1719

20+
Object clone() throws CloneNotSupportedException;
21+
1822
}

src/main/java/com/rabbitmq/client/impl/DefaultCredentialsProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ public void setUsername(String username) {
2828
public void setPassword(String password) {
2929
this.password = password;
3030
}
31-
31+
3232
}

0 commit comments

Comments
 (0)