From da240f2d975a5ef866394de5d8258ffeb843f4b5 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Mon, 11 Sep 2017 14:26:53 +0000 Subject: [PATCH] Fix ResultSet#toBoolean() not working properly for all dialects The SQL type of boolean type attributes in ReviewDb classes is char(1). The content of such columns is 'Y'/'N'. According to the specification, the method ResultSet#toBoolean() is only defined when the content is 0/1 for numeric or '0'/'1' for char types columns: [1]. [1] http://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html#getBoolean-int- Bug: Issue 7188 Change-Id: Iac9420d0aa789f1804052b2034def259c5ea359e --- .../google/gerrit/server/schema/Schema_139.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_139.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_139.java index be919a1943..4dfc41a01c 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_139.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/Schema_139.java @@ -15,6 +15,8 @@ package com.google.gerrit.server.schema; import com.google.auto.value.AutoValue; +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; import com.google.common.collect.ListMultimap; import com.google.common.collect.MultimapBuilder; import com.google.gerrit.common.Nullable; @@ -92,11 +94,11 @@ public class Schema_139 extends SchemaVersion { ProjectWatch.builder() .project(new Project.NameKey(rs.getString(2))) .filter(rs.getString(3)) - .notifyAbandonedChanges(rs.getBoolean(4)) - .notifyAllComments(rs.getBoolean(5)) - .notifyNewChanges(rs.getBoolean(6)) - .notifyNewPatchSets(rs.getBoolean(7)) - .notifySubmittedChanges(rs.getBoolean(8)); + .notifyAbandonedChanges(toBoolean(rs.getString(4))) + .notifyAllComments(toBoolean(rs.getString(5))) + .notifyNewChanges(toBoolean(rs.getString(6))) + .notifyNewPatchSets(toBoolean(rs.getString(7))) + .notifySubmittedChanges(toBoolean(rs.getString(8))); imports.put(accountId, b.build()); } } @@ -196,4 +198,9 @@ public class Schema_139 extends SchemaVersion { abstract ProjectWatch build(); } } + + private static boolean toBoolean(String v) { + Preconditions.checkState(!Strings.isNullOrEmpty(v)); + return v.equals("Y"); + } }