You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2016/06/30 00:08:51 UTC

[1/2] commons-crypto git commit: try-with-resources.

Repository: commons-crypto
Updated Branches:
  refs/heads/master bd9dfcd71 -> b11f6ffae


try-with-resources.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/9ecfae27
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/9ecfae27
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/9ecfae27

Branch: refs/heads/master
Commit: 9ecfae271b00a66a5ca2618b32aa59e96a165473
Parents: bd9dfcd
Author: Gary Gregory <gg...@apache.org>
Authored: Wed Jun 29 17:07:28 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Wed Jun 29 17:07:28 2016 -0700

----------------------------------------------------------------------
 .../org/apache/commons/crypto/cipher/AbstractCipherTest.java    | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9ecfae27/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
index affca80..3da0511 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
@@ -75,8 +75,9 @@ public abstract class AbstractCipherTest {
 
     @Test
     public void closeTestNoInit() throws Exception {
-        CryptoCipher enc = getCipher(transformations[0]);
-        enc.close();
+        try (CryptoCipher enc = getCipher(transformations[0])) {
+            // nothing
+        }
     }
 
     @Test


Re: [1/2] commons-crypto git commit: try-with-resources.

Posted by sebb <se...@gmail.com>.
On 30 June 2016 at 01:08,  <gg...@apache.org> wrote:
> Repository: commons-crypto
> Updated Branches:
>   refs/heads/master bd9dfcd71 -> b11f6ffae
>
>
> try-with-resources.
>
> Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
> Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/9ecfae27
> Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/9ecfae27
> Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/9ecfae27
>
> Branch: refs/heads/master
> Commit: 9ecfae271b00a66a5ca2618b32aa59e96a165473
> Parents: bd9dfcd
> Author: Gary Gregory <gg...@apache.org>
> Authored: Wed Jun 29 17:07:28 2016 -0700
> Committer: Gary Gregory <gg...@apache.org>
> Committed: Wed Jun 29 17:07:28 2016 -0700
>
> ----------------------------------------------------------------------
>  .../org/apache/commons/crypto/cipher/AbstractCipherTest.java    | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/9ecfae27/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> ----------------------------------------------------------------------
> diff --git a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> index affca80..3da0511 100644
> --- a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> +++ b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> @@ -75,8 +75,9 @@ public abstract class AbstractCipherTest {
>
>      @Test
>      public void closeTestNoInit() throws Exception {
> -        CryptoCipher enc = getCipher(transformations[0]);
> -        enc.close();
> +        try (CryptoCipher enc = getCipher(transformations[0])) {
> +            // nothing
> +        }

-1

These are specifically designed to test init and close.

>      }
>
>      @Test
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [2/2] commons-crypto git commit: try-with-resources.

Posted by Stian Soiland-Reyes <st...@apache.org>.
Agree for readability (and any future stack traces) that .close()
should be explicit in the one test case that actually test an early
close() doesn't fail :)

On 30 June 2016 at 01:22, Gary Gregory <ga...@gmail.com> wrote:
> I disagree with the -1s, but hey, that's just me -1. Reverted.
>
> G
>
> On Wed, Jun 29, 2016 at 5:19 PM, sebb <se...@gmail.com> wrote:
>
>> On 30 June 2016 at 01:08,  <gg...@apache.org> wrote:
>> > try-with-resources.
>> >
>> > Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
>> > Commit:
>> http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/b11f6ffa
>> > Tree:
>> http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/b11f6ffa
>> > Diff:
>> http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/b11f6ffa
>> >
>> > Branch: refs/heads/master
>> > Commit: b11f6ffaecef327840c3f42b880937a267ac7637
>> > Parents: 9ecfae2
>> > Author: Gary Gregory <gg...@apache.org>
>> > Authored: Wed Jun 29 17:08:49 2016 -0700
>> > Committer: Gary Gregory <gg...@apache.org>
>> > Committed: Wed Jun 29 17:08:49 2016 -0700
>> >
>> > ----------------------------------------------------------------------
>> >  .../commons/crypto/cipher/AbstractCipherTest.java   | 16
>> ++++++++--------
>> >  1 file changed, 8 insertions(+), 8 deletions(-)
>> > ----------------------------------------------------------------------
>> >
>> >
>> >
>> http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/b11f6ffa/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
>> > ----------------------------------------------------------------------
>> > diff --git
>> a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
>> b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
>> > index 3da0511..65f1472 100644
>> > ---
>> a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
>> > +++
>> b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
>> > @@ -82,18 +82,18 @@ public abstract class AbstractCipherTest {
>> >
>> >      @Test
>> >      public void closeTestAfterInit() throws Exception {
>> > -        CryptoCipher enc = getCipher(transformations[0]);
>> > -        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"),
>> new IvParameterSpec(IV));
>> > -        enc.close();
>> > +        try (CryptoCipher enc = getCipher(transformations[0])) {
>> > +            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY,
>> "AES"), new IvParameterSpec(IV));
>> > +        }
>>
>> -1
>>
>> This is specifically designed to test  init and close
>> It's not helpful to hide the close in the try with resources block.
>>
>> >      }
>> >
>> >      @Test
>> >      public void reInitTest() throws Exception {
>> > -        CryptoCipher enc = getCipher(transformations[0]);
>> > -        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"),
>> new IvParameterSpec(IV));
>> > -        enc.init(Cipher.DECRYPT_MODE, new SecretKeySpec(KEY, "AES"),
>> new IvParameterSpec(IV));
>> > -        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"),
>> new IvParameterSpec(IV));
>> > -        enc.close();
>> > +        try (CryptoCipher enc = getCipher(transformations[0])) {
>> > +            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY,
>> "AES"), new IvParameterSpec(IV));
>> > +            enc.init(Cipher.DECRYPT_MODE, new SecretKeySpec(KEY,
>> "AES"), new IvParameterSpec(IV));
>> > +            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY,
>> "AES"), new IvParameterSpec(IV));
>> > +        }
>>
>> -1
>>
>> DItto
>>
>> >      }
>> >
>> >      @Test
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory



-- 
Stian Soiland-Reyes
Apache Taverna (incubating), Apache Commons
http://orcid.org/0000-0001-9842-9718

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [2/2] commons-crypto git commit: try-with-resources.

Posted by Gary Gregory <ga...@gmail.com>.
I disagree with the -1s, but hey, that's just me -1. Reverted.

G

On Wed, Jun 29, 2016 at 5:19 PM, sebb <se...@gmail.com> wrote:

> On 30 June 2016 at 01:08,  <gg...@apache.org> wrote:
> > try-with-resources.
> >
> > Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
> > Commit:
> http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/b11f6ffa
> > Tree:
> http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/b11f6ffa
> > Diff:
> http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/b11f6ffa
> >
> > Branch: refs/heads/master
> > Commit: b11f6ffaecef327840c3f42b880937a267ac7637
> > Parents: 9ecfae2
> > Author: Gary Gregory <gg...@apache.org>
> > Authored: Wed Jun 29 17:08:49 2016 -0700
> > Committer: Gary Gregory <gg...@apache.org>
> > Committed: Wed Jun 29 17:08:49 2016 -0700
> >
> > ----------------------------------------------------------------------
> >  .../commons/crypto/cipher/AbstractCipherTest.java   | 16
> ++++++++--------
> >  1 file changed, 8 insertions(+), 8 deletions(-)
> > ----------------------------------------------------------------------
> >
> >
> >
> http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/b11f6ffa/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> > ----------------------------------------------------------------------
> > diff --git
> a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> > index 3da0511..65f1472 100644
> > ---
> a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> > +++
> b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> > @@ -82,18 +82,18 @@ public abstract class AbstractCipherTest {
> >
> >      @Test
> >      public void closeTestAfterInit() throws Exception {
> > -        CryptoCipher enc = getCipher(transformations[0]);
> > -        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"),
> new IvParameterSpec(IV));
> > -        enc.close();
> > +        try (CryptoCipher enc = getCipher(transformations[0])) {
> > +            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY,
> "AES"), new IvParameterSpec(IV));
> > +        }
>
> -1
>
> This is specifically designed to test  init and close
> It's not helpful to hide the close in the try with resources block.
>
> >      }
> >
> >      @Test
> >      public void reInitTest() throws Exception {
> > -        CryptoCipher enc = getCipher(transformations[0]);
> > -        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"),
> new IvParameterSpec(IV));
> > -        enc.init(Cipher.DECRYPT_MODE, new SecretKeySpec(KEY, "AES"),
> new IvParameterSpec(IV));
> > -        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"),
> new IvParameterSpec(IV));
> > -        enc.close();
> > +        try (CryptoCipher enc = getCipher(transformations[0])) {
> > +            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY,
> "AES"), new IvParameterSpec(IV));
> > +            enc.init(Cipher.DECRYPT_MODE, new SecretKeySpec(KEY,
> "AES"), new IvParameterSpec(IV));
> > +            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY,
> "AES"), new IvParameterSpec(IV));
> > +        }
>
> -1
>
> DItto
>
> >      }
> >
> >      @Test
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: [2/2] commons-crypto git commit: try-with-resources.

Posted by sebb <se...@gmail.com>.
On 30 June 2016 at 01:08,  <gg...@apache.org> wrote:
> try-with-resources.
>
> Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
> Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/b11f6ffa
> Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/b11f6ffa
> Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/b11f6ffa
>
> Branch: refs/heads/master
> Commit: b11f6ffaecef327840c3f42b880937a267ac7637
> Parents: 9ecfae2
> Author: Gary Gregory <gg...@apache.org>
> Authored: Wed Jun 29 17:08:49 2016 -0700
> Committer: Gary Gregory <gg...@apache.org>
> Committed: Wed Jun 29 17:08:49 2016 -0700
>
> ----------------------------------------------------------------------
>  .../commons/crypto/cipher/AbstractCipherTest.java   | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/b11f6ffa/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> ----------------------------------------------------------------------
> diff --git a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> index 3da0511..65f1472 100644
> --- a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> +++ b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
> @@ -82,18 +82,18 @@ public abstract class AbstractCipherTest {
>
>      @Test
>      public void closeTestAfterInit() throws Exception {
> -        CryptoCipher enc = getCipher(transformations[0]);
> -        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
> -        enc.close();
> +        try (CryptoCipher enc = getCipher(transformations[0])) {
> +            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
> +        }

-1

This is specifically designed to test  init and close
It's not helpful to hide the close in the try with resources block.

>      }
>
>      @Test
>      public void reInitTest() throws Exception {
> -        CryptoCipher enc = getCipher(transformations[0]);
> -        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
> -        enc.init(Cipher.DECRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
> -        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
> -        enc.close();
> +        try (CryptoCipher enc = getCipher(transformations[0])) {
> +            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
> +            enc.init(Cipher.DECRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
> +            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
> +        }

-1

DItto

>      }
>
>      @Test
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[2/2] commons-crypto git commit: try-with-resources.

Posted by gg...@apache.org.
try-with-resources.

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/b11f6ffa
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/b11f6ffa
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/b11f6ffa

Branch: refs/heads/master
Commit: b11f6ffaecef327840c3f42b880937a267ac7637
Parents: 9ecfae2
Author: Gary Gregory <gg...@apache.org>
Authored: Wed Jun 29 17:08:49 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Wed Jun 29 17:08:49 2016 -0700

----------------------------------------------------------------------
 .../commons/crypto/cipher/AbstractCipherTest.java   | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/b11f6ffa/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
index 3da0511..65f1472 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
@@ -82,18 +82,18 @@ public abstract class AbstractCipherTest {
 
     @Test
     public void closeTestAfterInit() throws Exception {
-        CryptoCipher enc = getCipher(transformations[0]);
-        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
-        enc.close();
+        try (CryptoCipher enc = getCipher(transformations[0])) {
+            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
+        }
     }
 
     @Test
     public void reInitTest() throws Exception {
-        CryptoCipher enc = getCipher(transformations[0]);
-        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
-        enc.init(Cipher.DECRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
-        enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
-        enc.close();
+        try (CryptoCipher enc = getCipher(transformations[0])) {
+            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
+            enc.init(Cipher.DECRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
+            enc.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(KEY, "AES"), new IvParameterSpec(IV));
+        }
     }
 
     @Test