[libpostgresql-jdbc-java] 25/128: fix cancelTimer bug reported by Andri Redko. now cancel timer when connection is closed make sure timer is cancelled if there is an exception in execute

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:18:27 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to annotated tag REL9_3_1100
in repository libpostgresql-jdbc-java.

commit 9387af3e12f5827a909141f8c137b4690811c801
Author: Dave Cramer <davecramer at gmail.com>
Date:   Fri Jan 11 11:34:44 2013 -0500

    fix cancelTimer bug reported by Andri Redko.
    now cancel timer when connection is closed
    make sure timer is cancelled if there is an exception in execute
---
 org/postgresql/jdbc2/AbstractJdbc2Statement.java | 32 ++++++++++++++++++------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/org/postgresql/jdbc2/AbstractJdbc2Statement.java b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
index 484d69f..7671cf6 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2Statement.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2Statement.java
@@ -46,7 +46,7 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
     protected final int resultsettype;   // the resultset type to return (ResultSet.TYPE_xxx)
     protected final int concurrency;   // is it updateable or not?     (ResultSet.CONCUR_xxx)
     protected int fetchdirection = ResultSet.FETCH_FORWARD;  // fetch direction hint (currently ignored)
-    private TimerTask cancelTimer=null;
+    private volatile TimerTask cancelTimer=null;
 
     /**
      * Does the caller of execute/executeUpdate want generated keys for this
@@ -552,16 +552,20 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
 
         StatementResultHandler handler = new StatementResultHandler();
         result = null;
+        try
+        {
+            
+        
         connection.getQueryExecutor().execute(queryToExecute,
                                               queryParameters,
                                               handler,
                                               maxrows,
                                               fetchSize,
                                               flags);
-        if ( cancelTimer != null )
+        }
+        finally
         {
-        	cancelTimer.cancel();
-        	cancelTimer=null;
+            killTimer();
         }
         result = firstUnclosedResult = handler.getResults();
 
@@ -714,10 +718,7 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
                                     PSQLState.INVALID_PARAMETER_VALUE);
 
         if (seconds == 0) {
-            if ( cancelTimer != null ) {
-                cancelTimer.cancel();
-        	    cancelTimer = null;
-            }
+            killTimer();
             return;
         }
 
@@ -728,6 +729,10 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
                     AbstractJdbc2Statement.this.cancel();
                 } catch (SQLException e) {
                 }
+                finally
+                {
+                    killTimer();
+                }
             }
         };
         
@@ -853,6 +858,8 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
         if (isClosed)
             return ;
 
+        killTimer();
+        
         closeForNextExecution();
 
         if (preparedQuery != null)
@@ -3408,4 +3415,13 @@ public abstract class AbstractJdbc2Statement implements BaseStatement
         throw Driver.notImplemented(this.getClass(), "registerOutParameter(int,int,String)");
     }
 
+    private synchronized void killTimer()
+    {
+        if ( cancelTimer != null )
+        {
+            cancelTimer.cancel();
+            cancelTimer = null;
+        }
+            
+    }
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list