calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [04/50] [abbrv] calcite-avatica git commit: [CALCITE-1667] Forbid calls to JDK APIs that use the default locale, time zone or character set
Date Thu, 30 Mar 2017 21:37:54 GMT
[CALCITE-1667] Forbid calls to JDK APIs that use the default locale, time zone or character set

Use the "forbidden-apis" maven plugin to detect calls to such APIs.
Eliminate calls to such APIs.


Project: http://git-wip-us.apache.org/repos/asf/calcite-avatica/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite-avatica/commit/75152c5b
Tree: http://git-wip-us.apache.org/repos/asf/calcite-avatica/tree/75152c5b
Diff: http://git-wip-us.apache.org/repos/asf/calcite-avatica/diff/75152c5b

Branch: refs/heads/master
Commit: 75152c5b7fd62f60c6cdfb86605af8b34a129898
Parents: c90fddf
Author: Julian Hyde <jhyde@apache.org>
Authored: Fri Mar 3 00:05:23 2017 -0800
Committer: Julian Hyde <jhyde@apache.org>
Committed: Fri Mar 3 11:04:28 2017 -0800

----------------------------------------------------------------------
 core/src/main/codegen/templates/Parser.jj       |  9 ++-
 .../apache/calcite/adapter/jdbc/JdbcSchema.java |  3 +-
 .../config/CalciteConnectionProperty.java       | 28 +++++++++-
 .../apache/calcite/interpreter/Interpreter.java |  3 +-
 .../org/apache/calcite/jdbc/CalciteSchema.java  |  7 ++-
 .../calcite/materialize/TileSuggester.java      |  4 +-
 .../org/apache/calcite/rel/core/Correlate.java  |  2 +-
 .../java/org/apache/calcite/rel/core/Join.java  |  2 +-
 .../apache/calcite/rel/core/JoinRelType.java    |  5 ++
 .../calcite/rel/externalize/RelJsonReader.java  |  4 +-
 .../calcite/rel/rel2sql/RelToSqlConverter.java  |  8 ++-
 .../calcite/rel/rel2sql/SqlImplementor.java     |  3 +-
 .../calcite/rel/rules/DateRangeRules.java       |  4 +-
 .../rel/rules/MultiJoinOptimizeBushyRule.java   |  5 +-
 .../java/org/apache/calcite/rex/RexBuilder.java |  6 +-
 .../org/apache/calcite/runtime/HttpUtils.java   |  8 ++-
 .../apache/calcite/runtime/SqlFunctions.java    |  8 ++-
 .../java/org/apache/calcite/sql/JoinType.java   |  5 ++
 .../org/apache/calcite/sql/SemiJoinType.java    |  5 ++
 .../org/apache/calcite/sql/SqlAccessType.java   |  6 +-
 .../org/apache/calcite/sql/SqlCollation.java    |  3 +-
 .../java/org/apache/calcite/sql/SqlDialect.java |  7 ++-
 .../java/org/apache/calcite/sql/SqlKind.java    |  4 ++
 .../java/org/apache/calcite/sql/SqlUtil.java    | 10 ++--
 .../apache/calcite/sql/advise/SqlAdvisor.java   |  4 +-
 .../calcite/sql/advise/SqlSimpleParser.java     |  3 +-
 .../calcite/sql/parser/SqlParserUtil.java       |  6 +-
 .../calcite/sql/pretty/SqlPrettyWriter.java     | 10 +++-
 .../apache/calcite/sql/type/SqlTypeName.java    |  7 +--
 .../sql/util/ReflectiveSqlOperatorTable.java    |  3 +-
 .../calcite/sql/validate/SqlValidatorImpl.java  |  3 +-
 .../org/apache/calcite/tools/RelBuilder.java    |  3 +-
 .../org/apache/calcite/util/ConversionUtil.java | 11 ++--
 .../java/org/apache/calcite/util/NameMap.java   |  4 +-
 .../org/apache/calcite/util/NameMultimap.java   |  4 +-
 .../java/org/apache/calcite/util/NameSet.java   |  6 +-
 .../java/org/apache/calcite/util/NlsString.java |  3 +-
 .../org/apache/calcite/util/NumberUtil.java     | 16 ++++--
 .../java/org/apache/calcite/util/Sources.java   | 12 +---
 .../java/org/apache/calcite/util/Template.java  |  8 +--
 .../java/org/apache/calcite/util/Unsafe.java    | 54 ++++++++++++++++++
 .../main/java/org/apache/calcite/util/Util.java | 58 +++++++++++++++++++-
 .../apache/calcite/util/ZonelessDatetime.java   |  3 +-
 .../calcite/util/javac/JaninoCompiler.java      |  3 +-
 .../calcite/util/trace/CalciteTimingTracer.java |  4 +-
 .../calcite/jdbc/CalciteRemoteDriverTest.java   | 31 +++++++----
 .../org/apache/calcite/rex/RexExecutorTest.java |  6 +-
 .../calcite/sql/parser/SqlParserTest.java       | 10 ++--
 .../calcite/sql/test/SqlOperatorBaseTest.java   | 12 ++--
 .../sql/validate/SqlValidatorUtilTest.java      | 10 ++--
 .../org/apache/calcite/test/CalciteAssert.java  | 13 +++--
 .../org/apache/calcite/test/DiffRepository.java |  3 +-
 .../org/apache/calcite/test/DiffTestCase.java   | 55 ++++++-------------
 .../java/org/apache/calcite/test/JdbcTest.java  | 15 ++---
 .../org/apache/calcite/test/QuidemTest.java     | 12 ++--
 .../calcite/test/RexImplicationCheckerTest.java |  7 ++-
 .../org/apache/calcite/test/RexProgramTest.java |  3 +-
 .../apache/calcite/test/SqlFunctionsTest.java   |  4 +-
 .../org/apache/calcite/test/SqlLimitsTest.java  |  6 +-
 .../org/apache/calcite/test/SqlLineTest.java    | 13 +++--
 .../org/apache/calcite/test/SqlTestGen.java     |  5 +-
 .../apache/calcite/test/SqlValidatorTest.java   |  4 +-
 .../ConcurrentTestCommandExecutor.java          |  6 +-
 .../concurrent/ConcurrentTestCommandScript.java | 45 +++++++--------
 .../java/org/apache/calcite/util/Smalls.java    | 14 +++--
 .../java/org/apache/calcite/util/UtilTest.java  | 17 +++---
 .../adapter/druid/DruidConnectionImpl.java      | 11 +++-
 .../calcite/adapter/druid/DruidQuery.java       |  2 +-
 .../calcite/adapter/druid/Granularity.java      |  4 +-
 .../elasticsearch/ElasticsearchFilter.java      |  4 +-
 .../calcite/adapter/csv/CsvSchemaFactory.java   |  3 +-
 .../java/org/apache/calcite/test/CsvTest.java   |  3 +-
 .../apache/calcite/example/maze/MazeTable.java  |  3 +-
 .../apache/calcite/adapter/file/FileReader.java |  8 +--
 .../calcite/adapter/file/FileRowConverter.java  | 28 ++++++----
 .../apache/calcite/linq4j/test/Linq4jTest.java  | 33 ++++++-----
 .../calcite/adapter/tpcds/TpcdsSchema.java      |  5 +-
 .../apache/calcite/adapter/tpch/TpchSchema.java | 13 +++--
 pom.xml                                         | 57 ++++++++++++++++++-
 .../calcite/adapter/spark/SparkHandlerImpl.java | 16 +++---
 .../calcite/adapter/spark/SparkRules.java       |  3 +-
 .../splunk/search/SplunkConnectionImpl.java     | 32 ++++++-----
 src/main/config/forbidden-apis/signatures.txt   | 42 ++++++++++++++
 83 files changed, 622 insertions(+), 310 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/codegen/templates/Parser.jj
----------------------------------------------------------------------
diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj
index dcc0558..b070530 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -115,6 +115,7 @@ import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Collections;
 import java.util.List;
+import java.util.Locale;
 
 import static org.apache.calcite.util.Static.RESOURCE;
 
@@ -3036,7 +3037,8 @@ SqlSetOption SqlSetOption(SqlParserPos pos, String scope) :
         |
             <ON> {
                 // OFF is handled by SimpleIdentifier, ON handled here.
-                val = new SqlIdentifier(token.image.toUpperCase(), getPos());
+                val = new SqlIdentifier(token.image.toUpperCase(Locale.ROOT),
+                    getPos());
             }
         )
         {
@@ -3050,7 +3052,8 @@ SqlSetOption SqlSetOption(SqlParserPos pos, String scope) :
             name = CompoundIdentifier()
         |
             <ALL> {
-                name = new SqlIdentifier(token.image.toUpperCase(), getPos());
+                name = new SqlIdentifier(token.image.toUpperCase(Locale.ROOT),
+                    getPos());
             }
         )
         {
@@ -3092,7 +3095,7 @@ String Scope() :
 {
 }
 {
-    ( <SYSTEM> | <SESSION> ) { return token.image.toUpperCase(); }
+    ( <SYSTEM> | <SESSION> ) { return token.image.toUpperCase(Locale.ROOT); }
 }
 
 <#if parser.createStatementParserMethods?size != 0>

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java
index 5ac3a38..faf0e94 100644
--- a/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java
+++ b/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcSchema.java
@@ -46,6 +46,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Collection;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import javax.sql.DataSource;
@@ -210,7 +211,7 @@ public class JdbcSchema implements Schema {
         final String tableTypeName2 =
             tableTypeName == null
             ? null
-            : tableTypeName.toUpperCase().replace(' ', '_');
+            : tableTypeName.toUpperCase(Locale.ROOT).replace(' ', '_');
         final TableType tableType =
             Util.enumVal(TableType.OTHER, tableTypeName2);
         if (tableType == TableType.OTHER  && tableTypeName2 != null) {

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/config/CalciteConnectionProperty.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/config/CalciteConnectionProperty.java b/core/src/main/java/org/apache/calcite/config/CalciteConnectionProperty.java
index 86fbb6a..b576aac 100644
--- a/core/src/main/java/org/apache/calcite/config/CalciteConnectionProperty.java
+++ b/core/src/main/java/org/apache/calcite/config/CalciteConnectionProperty.java
@@ -21,13 +21,15 @@ import org.apache.calcite.avatica.util.Casing;
 import org.apache.calcite.avatica.util.Quoting;
 import org.apache.calcite.model.JsonSchema;
 import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.util.Bug;
 
 import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 
 import static org.apache.calcite.avatica.ConnectionConfigImpl.PropEnv;
-import static org.apache.calcite.avatica.ConnectionConfigImpl.parse;
 
 /**
  * Properties that may be specified on the JDBC connect string.
@@ -151,7 +153,7 @@ public enum CalciteConnectionProperty implements ConnectionProperty {
   static {
     NAME_TO_PROPS = new HashMap<>();
     for (CalciteConnectionProperty p : CalciteConnectionProperty.values()) {
-      NAME_TO_PROPS.put(p.camelName.toUpperCase(), p);
+      NAME_TO_PROPS.put(p.camelName.toUpperCase(Locale.ROOT), p);
       NAME_TO_PROPS.put(p.name(), p);
     }
   }
@@ -194,7 +196,27 @@ public enum CalciteConnectionProperty implements ConnectionProperty {
   }
 
   public PropEnv wrap(Properties properties) {
-    return new PropEnv(parse(properties, NAME_TO_PROPS), this);
+    return new PropEnv(parse2(properties, NAME_TO_PROPS), this);
+  }
+
+  /** Fixed version of
+   * {@link org.apache.calcite.avatica.ConnectionConfigImpl#parse}
+   * until we upgrade Avatica. */
+  private static Map<ConnectionProperty, String> parse2(Properties properties,
+      Map<String, ? extends ConnectionProperty> nameToProps) {
+    Bug.upgrade("avatica-1.10");
+    final Map<ConnectionProperty, String> map = new LinkedHashMap<>();
+    for (String name : properties.stringPropertyNames()) {
+      final ConnectionProperty connectionProperty =
+          nameToProps.get(name.toUpperCase(Locale.ROOT));
+      if (connectionProperty == null) {
+        // For now, don't throw. It messes up sub-projects.
+        //throw new RuntimeException("Unknown property '" + name + "'");
+        continue;
+      }
+      map.put(connectionProperty, properties.getProperty(name));
+    }
+    return map;
   }
 
 }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java b/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java
index 0e154eb..51aa082 100644
--- a/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java
+++ b/core/src/main/java/org/apache/calcite/interpreter/Interpreter.java
@@ -49,6 +49,7 @@ import com.google.common.collect.Maps;
 import java.math.BigDecimal;
 import java.util.ArrayDeque;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.NoSuchElementException;
 
@@ -211,7 +212,7 @@ public class Interpreter extends AbstractEnumerable<Object[]>
                 if (s0 == null) {
                   return null;
                 }
-                return s0.toUpperCase();
+                return s0.toUpperCase(Locale.ROOT);
               }
               if (call.getOperator() == SqlStdOperatorTable.SUBSTRING) {
                 argScalar.execute(context, args);

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java b/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
index cb61627..4b1bc02 100644
--- a/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
+++ b/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
@@ -40,6 +40,7 @@ import com.google.common.collect.Lists;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.NavigableMap;
 import java.util.NavigableSet;
@@ -347,14 +348,16 @@ public abstract class CalciteSchema {
   protected static <V> NavigableMap<String, V> find(NavigableMap<String, V> map,
       String s) {
     assert map.comparator() == NameSet.COMPARATOR;
-    return map.subMap(s.toUpperCase(), true, s.toLowerCase(), true);
+    return map.subMap(s.toUpperCase(Locale.ROOT), true,
+        s.toLowerCase(Locale.ROOT), true);
   }
 
   /** Returns a subset of a set whose values match the given string
    * case-insensitively. */
   protected static Iterable<String> find(NavigableSet<String> set, String name) {
     assert set.comparator() == NameSet.COMPARATOR;
-    return set.subSet(name.toUpperCase(), true, name.toLowerCase(), true);
+    return set.subSet(name.toUpperCase(Locale.ROOT), true,
+        name.toLowerCase(Locale.ROOT), true);
   }
 
   /** Creates a root schema.

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/materialize/TileSuggester.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/materialize/TileSuggester.java b/core/src/main/java/org/apache/calcite/materialize/TileSuggester.java
index 29b54b9..e94781d 100644
--- a/core/src/main/java/org/apache/calcite/materialize/TileSuggester.java
+++ b/core/src/main/java/org/apache/calcite/materialize/TileSuggester.java
@@ -16,6 +16,8 @@
  */
 package org.apache.calcite.materialize;
 
+import org.apache.calcite.util.Util;
+
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -59,7 +61,7 @@ public class TileSuggester {
 
   public Iterable<? extends Lattice.Tile> tiles() {
     final Algorithm algorithm = new MonteCarloAlgorithm();
-    final PrintWriter pw = new PrintWriter(System.out);
+    final PrintWriter pw = Util.printWriter(System.out);
     final Progress progress = new ArgumentUtils.TextProgress(pw);
     final StatisticsProvider statisticsProvider =
         new StatisticsProviderImpl(lattice);

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/rel/core/Correlate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Correlate.java b/core/src/main/java/org/apache/calcite/rel/core/Correlate.java
index 1af9f80..6f218b1 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Correlate.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Correlate.java
@@ -156,7 +156,7 @@ public abstract class Correlate extends BiRel {
   @Override public RelWriter explainTerms(RelWriter pw) {
     return super.explainTerms(pw)
         .item("correlation", correlationId)
-        .item("joinType", joinType.name().toLowerCase())
+        .item("joinType", joinType.lowerName)
         .item("requiredColumns", requiredColumns.toString());
   }
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/rel/core/Join.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Join.java b/core/src/main/java/org/apache/calcite/rel/core/Join.java
index 2952fd1..a9e0441 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Join.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Join.java
@@ -204,7 +204,7 @@ public abstract class Join extends BiRel {
   @Override public RelWriter explainTerms(RelWriter pw) {
     return super.explainTerms(pw)
         .item("condition", condition)
-        .item("joinType", joinType.name().toLowerCase())
+        .item("joinType", joinType.lowerName)
         .itemIf(
             "systemFields",
             getSystemFieldList(),

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/rel/core/JoinRelType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/core/JoinRelType.java b/core/src/main/java/org/apache/calcite/rel/core/JoinRelType.java
index 677021e..5d75742 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/JoinRelType.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/JoinRelType.java
@@ -16,12 +16,17 @@
  */
 package org.apache.calcite.rel.core;
 
+import java.util.Locale;
+
 /**
  * Enumeration of join types.
  */
 public enum JoinRelType {
   INNER, LEFT, RIGHT, FULL;
 
+  /** Lower-case name. */
+  public final String lowerName = name().toLowerCase(Locale.ROOT);
+
   /**
    * Returns whether a join of this type may generate NULL values on the
    * right-hand side.

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/rel/externalize/RelJsonReader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/externalize/RelJsonReader.java b/core/src/main/java/org/apache/calcite/rel/externalize/RelJsonReader.java
index 57a7f76..a3d6dd4 100644
--- a/core/src/main/java/org/apache/calcite/rel/externalize/RelJsonReader.java
+++ b/core/src/main/java/org/apache/calcite/rel/externalize/RelJsonReader.java
@@ -46,6 +46,7 @@ import java.util.AbstractList;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -188,7 +189,8 @@ public class RelJsonReader {
       }
 
       public <E extends Enum<E>> E getEnum(String tag, Class<E> enumClass) {
-        return Util.enumVal(enumClass, getString(tag).toUpperCase());
+        return Util.enumVal(enumClass,
+            getString(tag).toUpperCase(Locale.ROOT));
       }
 
       public List<RexNode> getExpressionList(String tag) {

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
index c2fe284..96cfac7 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
@@ -65,6 +65,7 @@ import com.google.common.collect.Lists;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -358,9 +359,10 @@ public class RelToSqlConverter extends SqlImplementor
       RelDataType rowType) {
     String name = rowType.getFieldNames().get(selectList.size());
     String alias = SqlValidatorUtil.getAlias(node, -1);
-    if (name.toLowerCase().startsWith("expr$")) {
-      //Put it in ordinalMap
-      ordinalMap.put(name.toLowerCase(), node);
+    final String lowerName = name.toLowerCase(Locale.ROOT);
+    if (lowerName.startsWith("expr$")) {
+      // Put it in ordinalMap
+      ordinalMap.put(lowerName, node);
     } else if (alias == null || !alias.equals(name)) {
       node = SqlStdOperatorTable.AS.createCall(
           POS, node, new SqlIdentifier(name, POS));

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
index 206716b..3c92f29 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
@@ -84,6 +84,7 @@ import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
@@ -831,7 +832,7 @@ public abstract class SqlImplementor {
         if (ordinal < fields.size()) {
           RelDataTypeField field = fields.get(ordinal);
           final SqlNode mappedSqlNode =
-              ordinalMap.get(field.getName().toLowerCase());
+              ordinalMap.get(field.getName().toLowerCase(Locale.ROOT));
           if (mappedSqlNode != null) {
             return mappedSqlNode;
           }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/rel/rules/DateRangeRules.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/DateRangeRules.java b/core/src/main/java/org/apache/calcite/rel/rules/DateRangeRules.java
index a052140..3102f42 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/DateRangeRules.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/DateRangeRules.java
@@ -16,7 +16,6 @@
  */
 package org.apache.calcite.rel.rules;
 
-import org.apache.calcite.avatica.util.DateTimeUtils;
 import org.apache.calcite.avatica.util.TimeUnitRange;
 import org.apache.calcite.plan.RelOptRule;
 import org.apache.calcite.plan.RelOptRuleCall;
@@ -36,6 +35,7 @@ import org.apache.calcite.sql.fun.SqlStdOperatorTable;
 import org.apache.calcite.tools.RelBuilder;
 import org.apache.calcite.tools.RelBuilderFactory;
 import org.apache.calcite.util.Bug;
+import org.apache.calcite.util.Util;
 
 import com.google.common.base.Predicate;
 import com.google.common.collect.BoundType;
@@ -290,7 +290,7 @@ public abstract class DateRangeRules {
         final Calendar c;
         switch (timeUnit) {
         case YEAR:
-          c = Calendar.getInstance(DateTimeUtils.GMT_ZONE);
+          c = Util.calendar();
           c.clear();
           c.set(v, Calendar.JANUARY, 1);
           s2.add(baz(timeUnit, comparison, c));

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java b/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java
index b63e3a4..790aed7 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java
@@ -69,8 +69,9 @@ public class MultiJoinOptimizeBushyRule extends RelOptRule {
   public static final MultiJoinOptimizeBushyRule INSTANCE =
       new MultiJoinOptimizeBushyRule(RelFactories.LOGICAL_BUILDER);
 
-  private final PrintWriter pw =
-      CalcitePrepareImpl.DEBUG ? new PrintWriter(System.out, true) : null;
+  private final PrintWriter pw = CalcitePrepareImpl.DEBUG
+      ? Util.printWriter(System.out)
+      : null;
 
   /** Creates an MultiJoinOptimizeBushyRule. */
   public MultiJoinOptimizeBushyRule(RelBuilderFactory relBuilderFactory) {

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
index 3e34ec9..2a4667c 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexBuilder.java
@@ -1402,14 +1402,14 @@ public class RexBuilder {
       if (o instanceof Calendar) {
         return o;
       }
-      calendar = Calendar.getInstance(DateTimeUtils.GMT_ZONE);
+      calendar = Util.calendar();
       calendar.setTimeInMillis((Integer) o);
       return calendar;
     case DATE:
       if (o instanceof Calendar) {
         return o;
       }
-      calendar = Calendar.getInstance(DateTimeUtils.GMT_ZONE);
+      calendar = Util.calendar();
       calendar.setTimeInMillis(0);
       calendar.add(Calendar.DAY_OF_YEAR, (Integer) o);
       return calendar;
@@ -1417,7 +1417,7 @@ public class RexBuilder {
       if (o instanceof Calendar) {
         return o;
       }
-      calendar = Calendar.getInstance(DateTimeUtils.GMT_ZONE);
+      calendar = Util.calendar();
       calendar.setTimeInMillis((Long) o);
       return calendar;
     default:

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java b/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java
index 50deeef..bc790d6 100644
--- a/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java
+++ b/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java
@@ -25,6 +25,7 @@ import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.Map;
 import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.HttpsURLConnection;
@@ -67,8 +68,8 @@ public class HttpUtils {
         if (i++ != 0) {
           out.append("&");
         }
-        out.append(URLEncoder.encode(me.getKey(), "UTF-8"));
-        out.append("=")
+        out.append(URLEncoder.encode(me.getKey(), "UTF-8"))
+            .append("=")
             .append(URLEncoder.encode(me.getValue(), "UTF-8"));
       }
     } catch (UnsupportedEncodingException ignore) {
@@ -136,7 +137,8 @@ public class HttpUtils {
       return conn.getInputStream();
     }
     conn.setDoOutput(true);
-    try (Writer w = new OutputStreamWriter(conn.getOutputStream())) {
+    try (Writer w = new OutputStreamWriter(conn.getOutputStream(),
+        StandardCharsets.UTF_8)) {
       w.write(data.toString());
       w.flush(); // Get the response
       return conn.getInputStream();

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
index 634067c..baa2c6f 100644
--- a/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
@@ -32,6 +32,7 @@ import org.apache.calcite.linq4j.function.NonDeterministic;
 import org.apache.calcite.linq4j.tree.Primitive;
 import org.apache.calcite.runtime.FlatLists.ComparableList;
 import org.apache.calcite.util.Bug;
+import org.apache.calcite.util.NumberUtil;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -45,6 +46,7 @@ import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.TimeZone;
@@ -66,7 +68,7 @@ import java.util.regex.Pattern;
 @Deterministic
 public class SqlFunctions {
   private static final DecimalFormat DOUBLE_FORMAT =
-      new DecimalFormat("0.0E0");
+      NumberUtil.decimalFormat("0.0E0");
 
   private static final TimeZone LOCAL_TZ = TimeZone.getDefault();
 
@@ -138,12 +140,12 @@ public class SqlFunctions {
 
   /** SQL UPPER(string) function. */
   public static String upper(String s) {
-    return s.toUpperCase();
+    return s.toUpperCase(Locale.ROOT);
   }
 
   /** SQL LOWER(string) function. */
   public static String lower(String s) {
-    return s.toLowerCase();
+    return s.toLowerCase(Locale.ROOT);
   }
 
   /** SQL INITCAP(string) function. */

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/JoinType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/JoinType.java b/core/src/main/java/org/apache/calcite/sql/JoinType.java
index 0e4cc05..4759324 100644
--- a/core/src/main/java/org/apache/calcite/sql/JoinType.java
+++ b/core/src/main/java/org/apache/calcite/sql/JoinType.java
@@ -18,6 +18,8 @@ package org.apache.calcite.sql;
 
 import org.apache.calcite.sql.parser.SqlParserPos;
 
+import java.util.Locale;
+
 /**
  * Enumerates the types of join.
  */
@@ -54,6 +56,9 @@ public enum JoinType {
    */
   COMMA;
 
+  /** Lower-case name. */
+  public final String lowerName = name().toLowerCase(Locale.ROOT);
+
   /**
    * Creates a parse-tree node representing an occurrence of this
    * condition type keyword at a particular position in the parsed

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/SemiJoinType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SemiJoinType.java b/core/src/main/java/org/apache/calcite/sql/SemiJoinType.java
index 38cabba..473e812 100644
--- a/core/src/main/java/org/apache/calcite/sql/SemiJoinType.java
+++ b/core/src/main/java/org/apache/calcite/sql/SemiJoinType.java
@@ -20,6 +20,8 @@ import org.apache.calcite.linq4j.CorrelateJoinType;
 import org.apache.calcite.rel.core.JoinRelType;
 import org.apache.calcite.sql.parser.SqlParserPos;
 
+import java.util.Locale;
+
 /**
  * Enumeration representing different join types used in correlation
  * relations.
@@ -48,6 +50,9 @@ public enum SemiJoinType {
    */
   ANTI;
 
+  /** Lower-case name. */
+  public final String lowerName = name().toLowerCase(Locale.ROOT);
+
   /**
    * Creates a parse-tree node representing an occurrence of this
    * condition type keyword at a particular position in the parsed

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/SqlAccessType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlAccessType.java b/core/src/main/java/org/apache/calcite/sql/SqlAccessType.java
index 5da1b56..5efab84 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlAccessType.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlAccessType.java
@@ -17,6 +17,7 @@
 package org.apache.calcite.sql;
 
 import java.util.EnumSet;
+import java.util.Locale;
 
 /**
  * SqlAccessType is represented by a set of allowed access types
@@ -54,10 +55,9 @@ public class SqlAccessType {
   public static SqlAccessType create(String[] accessNames) {
     assert accessNames != null;
     EnumSet<SqlAccessEnum> enumSet = EnumSet.noneOf(SqlAccessEnum.class);
-    for (int i = 0; i < accessNames.length; i++) {
+    for (String accessName : accessNames) {
       enumSet.add(
-          SqlAccessEnum.valueOf(
-              accessNames[i].trim().toUpperCase()));
+          SqlAccessEnum.valueOf(accessName.trim().toUpperCase(Locale.ROOT)));
     }
     return new SqlAccessType(enumSet);
   }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/SqlCollation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlCollation.java b/core/src/main/java/org/apache/calcite/sql/SqlCollation.java
index 66fd7ac..a3ac712 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlCollation.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlCollation.java
@@ -88,7 +88,8 @@ public class SqlCollation implements Serializable {
     this.wrappedCharset = SerializableCharset.forCharset(charset);
     locale = parseValues.getLocale();
     strength = parseValues.getStrength();
-    String c = charset.name().toUpperCase() + "$" + locale.toString();
+    String c =
+        charset.name().toUpperCase(Locale.ROOT) + "$" + locale.toString();
     if ((strength != null) && (strength.length() > 0)) {
       c += "$" + strength;
     }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
index d3ea0f7..3f9e6b0 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlDialect.java
@@ -27,6 +27,7 @@ import java.sql.SQLException;
 import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
 import java.util.List;
+import java.util.Locale;
 import java.util.regex.Pattern;
 
 /**
@@ -183,7 +184,8 @@ public class SqlDialect {
   public static DatabaseProduct getProduct(
       String productName,
       String productVersion) {
-    final String upperProductName = productName.toUpperCase().trim();
+    final String upperProductName =
+        productName.toUpperCase(Locale.ROOT).trim();
     switch (upperProductName) {
     case "ACCESS":
       return DatabaseProduct.ACCESS;
@@ -470,7 +472,8 @@ public class SqlDialect {
   public String quoteTimestampLiteral(Timestamp timestamp) {
     final SimpleDateFormat format =
         new SimpleDateFormat(
-            "'TIMESTAMP' ''yyyy-MM-DD HH:mm:SS''");
+            "'TIMESTAMP' ''yyyy-MM-DD HH:mm:SS''",
+            Locale.ROOT);
     format.setTimeZone(DateTimeUtils.GMT_ZONE);
     return format.format(timestamp);
   }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/SqlKind.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlKind.java b/core/src/main/java/org/apache/calcite/sql/SqlKind.java
index e3cff7c..8dbb55ef 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlKind.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlKind.java
@@ -18,6 +18,7 @@ package org.apache.calcite.sql;
 
 import java.util.Collection;
 import java.util.EnumSet;
+import java.util.Locale;
 import java.util.Set;
 
 /**
@@ -1006,6 +1007,9 @@ public enum SqlKind {
           LESS_THAN, GREATER_THAN,
           GREATER_THAN_OR_EQUAL, LESS_THAN_OR_EQUAL);
 
+  /** Lower-case name. */
+  public final String lowerName = name().toLowerCase(Locale.ROOT);
+
   /** Returns the kind that corresponds to this operator but in the opposite
    * direction. Or returns this, if this kind is not reversible.
    *

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/SqlUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlUtil.java b/core/src/main/java/org/apache/calcite/sql/SqlUtil.java
index 71e79c7..98e7f0e 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlUtil.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlUtil.java
@@ -54,6 +54,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import static org.apache.calcite.util.Static.RESOURCE;
@@ -743,8 +744,8 @@ public abstract class SqlUtil {
         if (i > 0) {
           ret.append(", ");
         }
-        ret.append("<").append(
-            typeList.get(i).toString().toUpperCase()).append(">");
+        final String t = typeList.get(i).toString().toUpperCase(Locale.ROOT);
+        ret.append("<").append(t).append(">");
       }
       ret.append(")'");
     } else {
@@ -752,9 +753,10 @@ public abstract class SqlUtil {
       values[0] = opName;
       ret.append("'");
       for (int i = 0; i < typeList.size(); i++) {
-        values[i + 1] = "<" + typeList.get(i).toString().toUpperCase() + ">";
+        final String t = typeList.get(i).toString().toUpperCase(Locale.ROOT);
+        values[i + 1] = "<" + t + ">";
       }
-      ret.append(MessageFormat.format(template, values));
+      ret.append(new MessageFormat(template, Locale.ROOT).format(values));
       ret.append("'");
       assert (typeList.size() + 1) == values.length;
     }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisor.java b/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisor.java
index 1b2481e..0216cc3 100644
--- a/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisor.java
+++ b/core/src/main/java/org/apache/calcite/sql/advise/SqlAdvisor.java
@@ -44,6 +44,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Locale;
 
 /**
  * An assistant which offers hints and corrections to a partially-formed SQL
@@ -54,7 +55,8 @@ public class SqlAdvisor {
 
   public static final Logger LOGGER = CalciteTrace.PARSER_LOGGER;
   private static final String HINT_TOKEN = "_suggest_";
-  private static final String UPPER_HINT_TOKEN = HINT_TOKEN.toUpperCase();
+  private static final String UPPER_HINT_TOKEN =
+      HINT_TOKEN.toUpperCase(Locale.ROOT);
 
   //~ Instance fields --------------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/advise/SqlSimpleParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/advise/SqlSimpleParser.java b/core/src/main/java/org/apache/calcite/sql/advise/SqlSimpleParser.java
index 85dfa10..f9a0d31 100644
--- a/core/src/main/java/org/apache/calcite/sql/advise/SqlSimpleParser.java
+++ b/core/src/main/java/org/apache/calcite/sql/advise/SqlSimpleParser.java
@@ -21,6 +21,7 @@ import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -379,7 +380,7 @@ public class SqlSimpleParser {
               }
             }
             String name = sql.substring(start, pos);
-            TokenType tokenType = map.get(name.toUpperCase());
+            TokenType tokenType = map.get(name.toUpperCase(Locale.ROOT));
             if (tokenType == null) {
               return new IdToken(TokenType.ID, name);
             } else {

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java b/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java
index 228b5f7..d4b7237 100644
--- a/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java
+++ b/core/src/main/java/org/apache/calcite/sql/parser/SqlParserUtil.java
@@ -135,7 +135,7 @@ public final class SqlParserUtil {
    * @param pattern {@link SimpleDateFormat}  pattern
    */
   public static void checkDateFormat(String pattern) {
-    SimpleDateFormat df = new SimpleDateFormat(pattern);
+    SimpleDateFormat df = new SimpleDateFormat(pattern, Locale.ROOT);
     Util.discard(df);
   }
 
@@ -279,9 +279,9 @@ public final class SqlParserUtil {
     }
     switch (casing) {
     case TO_UPPER:
-      return s.toUpperCase();
+      return s.toUpperCase(Locale.ROOT);
     case TO_LOWER:
-      return s.toLowerCase();
+      return s.toLowerCase(Locale.ROOT);
     default:
       return s;
     }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
index c2b206a..ec78b04 100644
--- a/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
+++ b/core/src/main/java/org/apache/calcite/sql/pretty/SqlPrettyWriter.java
@@ -22,6 +22,7 @@ import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlWriter;
 import org.apache.calcite.sql.util.SqlBuilder;
 import org.apache.calcite.sql.util.SqlString;
+import org.apache.calcite.util.Unsafe;
 import org.apache.calcite.util.Util;
 import org.apache.calcite.util.trace.CalciteLogger;
 
@@ -37,6 +38,7 @@ import java.util.ArrayDeque;
 import java.util.Deque;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Properties;
@@ -275,7 +277,7 @@ public class SqlPrettyWriter implements SqlWriter {
 
   public void reset() {
     pw.flush();
-    sw.getBuffer().setLength(0);
+    Unsafe.clear(sw);
     setNeedWhitespace(false);
     nextWhitespace = " ";
   }
@@ -821,7 +823,9 @@ public class SqlPrettyWriter implements SqlWriter {
   public void keyword(String s) {
     maybeWhitespace(s);
     pw.print(
-        isKeywordsLowerCase() ? s.toLowerCase() : s.toUpperCase());
+        isKeywordsLowerCase()
+            ? s.toLowerCase(Locale.ROOT)
+            : s.toUpperCase(Locale.ROOT));
     charCount += s.length();
     if (!s.equals("")) {
       setNeedWhitespace(needWhitespaceAfter(s));
@@ -1148,7 +1152,7 @@ public class SqlPrettyWriter implements SqlWriter {
     }
 
     private String stripPrefix(String name, int offset) {
-      return name.substring(offset, offset + 1).toLowerCase()
+      return name.substring(offset, offset + 1).toLowerCase(Locale.ROOT)
           + name.substring(offset + 1);
     }
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeName.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeName.java b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeName.java
index f55f9b9..f34ea11 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/SqlTypeName.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/SqlTypeName.java
@@ -16,7 +16,6 @@
  */
 package org.apache.calcite.sql.type;
 
-import org.apache.calcite.avatica.util.DateTimeUtils;
 import org.apache.calcite.avatica.util.TimeUnit;
 import org.apache.calcite.sql.SqlLiteral;
 import org.apache.calcite.sql.parser.SqlParserPos;
@@ -591,7 +590,7 @@ public enum SqlTypeName {
       return bytes;
 
     case DATE:
-      calendar = Calendar.getInstance(DateTimeUtils.GMT_ZONE);
+      calendar = Util.calendar();
       switch (limit) {
       case ZERO:
 
@@ -639,7 +638,7 @@ public enum SqlTypeName {
       if (beyond) {
         return null; // invalid values are impossible to represent
       }
-      calendar = Calendar.getInstance(DateTimeUtils.GMT_ZONE);
+      calendar = Util.calendar();
       switch (limit) {
       case ZERO:
 
@@ -664,7 +663,7 @@ public enum SqlTypeName {
       return calendar;
 
     case TIMESTAMP:
-      calendar = Calendar.getInstance(DateTimeUtils.GMT_ZONE);
+      calendar = Util.calendar();
       switch (limit) {
       case ZERO:
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java b/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java
index a9d2ae1..0812b24 100644
--- a/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java
+++ b/core/src/main/java/org/apache/calcite/sql/util/ReflectiveSqlOperatorTable.java
@@ -32,6 +32,7 @@ import com.google.common.collect.Multimap;
 import java.lang.reflect.Field;
 import java.util.Collection;
 import java.util.List;
+import java.util.Locale;
 
 /**
  * ReflectiveSqlOperatorTable implements the {@link SqlOperatorTable} interface
@@ -145,7 +146,7 @@ public abstract class ReflectiveSqlOperatorTable implements SqlOperatorTable {
    * store case-insensitively, even in a case-sensitive session. */
   private static class Key extends Pair<String, SqlSyntax> {
     Key(String name, SqlSyntax syntax) {
-      super(name.toUpperCase(), normalize(syntax));
+      super(name.toUpperCase(Locale.ROOT), normalize(syntax));
     }
 
     private static SqlSyntax normalize(SqlSyntax syntax) {

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index d270f57..eb2ea3b 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -111,6 +111,7 @@ import java.util.HashSet;
 import java.util.IdentityHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
@@ -3073,7 +3074,7 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
       names = Lists.transform(names,
           new Function<String, String>() {
             public String apply(String s) {
-              return s.toUpperCase();
+              return s.toUpperCase(Locale.ROOT);
             }
           });
     }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
index a0846c8..ddc0c43 100644
--- a/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
+++ b/core/src/main/java/org/apache/calcite/tools/RelBuilder.java
@@ -87,6 +87,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Locale;
 import java.util.Objects;
 import java.util.Set;
 import java.util.SortedSet;
@@ -431,7 +432,7 @@ public class RelBuilder {
           return field(inputCount, inputCount - 1 - inputOrdinal, p.i);
         }
         fields.add(
-            String.format("{aliases=%s,fieldName=%s}", p.e.left,
+            String.format(Locale.ROOT, "{aliases=%s,fieldName=%s}", p.e.left,
                 p.e.right.getName()));
       }
     }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/ConversionUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/ConversionUtil.java b/core/src/main/java/org/apache/calcite/util/ConversionUtil.java
index 193cc7c..29a2614 100644
--- a/core/src/main/java/org/apache/calcite/util/ConversionUtil.java
+++ b/core/src/main/java/org/apache/calcite/util/ConversionUtil.java
@@ -18,6 +18,7 @@ package org.apache.calcite.util;
 
 import java.nio.ByteOrder;
 import java.text.NumberFormat;
+import java.util.Locale;
 
 import static org.apache.calcite.util.Static.RESOURCE;
 
@@ -68,14 +69,12 @@ public class ConversionUtil {
     }
 
     int trick = radix * radix;
-    StringBuffer ret = new StringBuffer();
-    for (int i = 0; i < value.length; i++) {
-      ret.append(
-          Integer.toString(trick | (0x0ff & value[i]), radix).substring(
-              1));
+    StringBuilder ret = new StringBuilder();
+    for (byte b : value) {
+      ret.append(Integer.toString(trick | (0x0ff & b), radix).substring(1));
     }
 
-    return ret.toString().toUpperCase();
+    return ret.toString().toUpperCase(Locale.ROOT);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/NameMap.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/NameMap.java b/core/src/main/java/org/apache/calcite/util/NameMap.java
index a0c69bc..19a5507 100644
--- a/core/src/main/java/org/apache/calcite/util/NameMap.java
+++ b/core/src/main/java/org/apache/calcite/util/NameMap.java
@@ -18,6 +18,7 @@ package org.apache.calcite.util;
 
 import com.google.common.collect.ImmutableSortedMap;
 
+import java.util.Locale;
 import java.util.Map;
 import java.util.NavigableMap;
 import java.util.TreeMap;
@@ -62,7 +63,8 @@ public class NameMap<V> {
         return ImmutableSortedMap.of();
       }
     } else {
-      return map.subMap(name.toUpperCase(), true, name.toLowerCase(), true);
+      return map.subMap(name.toUpperCase(Locale.ROOT), true,
+          name.toLowerCase(Locale.ROOT), true);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/NameMultimap.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/NameMultimap.java b/core/src/main/java/org/apache/calcite/util/NameMultimap.java
index 1b3734a..4d42a29 100644
--- a/core/src/main/java/org/apache/calcite/util/NameMultimap.java
+++ b/core/src/main/java/org/apache/calcite/util/NameMultimap.java
@@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableList;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.NavigableMap;
 import java.util.TreeMap;
@@ -75,7 +76,8 @@ public class NameMultimap<V> {
       final ImmutableList.Builder<Map.Entry<String, V>> builder =
           ImmutableList.builder();
       NavigableMap<String, List<V>> m =
-          map.subMap(name.toUpperCase(), true, name.toLowerCase(), true);
+          map.subMap(name.toUpperCase(Locale.ROOT), true,
+              name.toLowerCase(Locale.ROOT), true);
       for (Map.Entry<String, List<V>> entry : m.entrySet()) {
         for (V v : entry.getValue()) {
           builder.add(Pair.of(entry.getKey(), v));

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/NameSet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/NameSet.java b/core/src/main/java/org/apache/calcite/util/NameSet.java
index ccdd5d5..a51f949 100644
--- a/core/src/main/java/org/apache/calcite/util/NameSet.java
+++ b/core/src/main/java/org/apache/calcite/util/NameSet.java
@@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableSortedSet;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Locale;
 import java.util.NavigableSet;
 import java.util.Set;
 import java.util.TreeSet;
@@ -77,7 +78,8 @@ public class NameSet {
         return ImmutableList.of();
       }
     } else {
-      return names.subSet(name.toUpperCase(), true, name.toLowerCase(), true);
+      return names.subSet(name.toUpperCase(Locale.ROOT), true,
+          name.toLowerCase(Locale.ROOT), true);
     }
   }
 
@@ -88,7 +90,7 @@ public class NameSet {
       return true;
     }
     if (!caseSensitive) {
-      final String s = names.ceiling(name.toLowerCase());
+      final String s = names.ceiling(name.toLowerCase(Locale.ROOT));
       return s != null
           && s.equalsIgnoreCase(name);
     }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/NlsString.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/NlsString.java b/core/src/main/java/org/apache/calcite/util/NlsString.java
index aa68eec..eee7884 100644
--- a/core/src/main/java/org/apache/calcite/util/NlsString.java
+++ b/core/src/main/java/org/apache/calcite/util/NlsString.java
@@ -27,6 +27,7 @@ import java.nio.charset.CharsetEncoder;
 import java.nio.charset.IllegalCharsetNameException;
 import java.nio.charset.UnsupportedCharsetException;
 import java.util.List;
+import java.util.Locale;
 import java.util.Objects;
 
 import static org.apache.calcite.util.Static.RESOURCE;
@@ -63,7 +64,7 @@ public class NlsString implements Comparable<NlsString> {
       SqlCollation collation) {
     assert value != null;
     if (null != charsetName) {
-      charsetName = charsetName.toUpperCase();
+      charsetName = charsetName.toUpperCase(Locale.ROOT);
       this.charsetName = charsetName;
       String javaCharsetName =
           SqlUtil.translateCharacterSetName(charsetName);

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/NumberUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/NumberUtil.java b/core/src/main/java/org/apache/calcite/util/NumberUtil.java
index a33b416..d0e2d84 100644
--- a/core/src/main/java/org/apache/calcite/util/NumberUtil.java
+++ b/core/src/main/java/org/apache/calcite/util/NumberUtil.java
@@ -20,10 +20,12 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.math.RoundingMode;
 import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
 import java.text.NumberFormat;
+import java.util.Locale;
 
 /**
- * Utility functions for working with numbers This class is JDK 1.4 compatible.
+ * Utility functions for working with numbers.
  */
 public class NumberUtil {
   private NumberUtil() {}
@@ -39,12 +41,10 @@ public class NumberUtil {
   static {
     // TODO: DecimalFormat uses ROUND_HALF_EVEN, not ROUND_HALF_UP
     // Float: precision of 7 (6 digits after .)
-    FLOAT_FORMATTER = new DecimalFormat();
-    FLOAT_FORMATTER.applyPattern("0.######E0");
+    FLOAT_FORMATTER = decimalFormat("0.######E0");
 
     // Double: precision of 16 (15 digits after .)
-    DOUBLE_FORMATTER = new DecimalFormat();
-    DOUBLE_FORMATTER.applyPattern("0.###############E0");
+    DOUBLE_FORMATTER = decimalFormat("0.###############E0");
 
     BIG_INT_TEN_POW = new BigInteger[20];
     BIG_INT_MIN_UNSCALED = new BigInteger[20];
@@ -64,6 +64,12 @@ public class NumberUtil {
 
   //~ Methods ----------------------------------------------------------------
 
+  /** Creates a format. Locale-independent. */
+  public static DecimalFormat decimalFormat(String pattern) {
+    return new DecimalFormat(pattern,
+        DecimalFormatSymbols.getInstance(Locale.ROOT));
+  }
+
   public static BigInteger powTen(int exponent) {
     if ((exponent >= 0) && (exponent < BIG_INT_TEN_POW.length)) {
       return BIG_INT_TEN_POW[exponent];

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/Sources.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/Sources.java b/core/src/main/java/org/apache/calcite/util/Sources.java
index 946102f..01a864a 100644
--- a/core/src/main/java/org/apache/calcite/util/Sources.java
+++ b/core/src/main/java/org/apache/calcite/util/Sources.java
@@ -20,13 +20,13 @@ import com.google.common.base.Preconditions;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.zip.GZIPInputStream;
 
 /**
@@ -57,11 +57,6 @@ public abstract class Sources {
     }
   }
 
-  private static String trim(String s, String suffix) {
-    String trimmed = trimOrNull(s, suffix);
-    return trimmed != null ? trimmed : s;
-  }
-
   /** Looks for a suffix on a path and returns
    * either the path with the suffix removed
    * or null. */
@@ -126,12 +121,9 @@ public abstract class Sources {
         final InputStream fis = openStream();
         is = new GZIPInputStream(fis);
       } else {
-        if (file != null) {
-          return new FileReader(file);
-        }
         is = openStream();
       }
-      return new InputStreamReader(is);
+      return new InputStreamReader(is, StandardCharsets.UTF_8);
     }
 
     public InputStream openStream() throws IOException {

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/Template.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/Template.java b/core/src/main/java/org/apache/calcite/util/Template.java
index 1936f8e..88d268a 100644
--- a/core/src/main/java/org/apache/calcite/util/Template.java
+++ b/core/src/main/java/org/apache/calcite/util/Template.java
@@ -86,7 +86,7 @@ public class Template extends MessageFormat {
    * @throws IllegalArgumentException if the pattern is invalid
    */
   public static Template of(String pattern, Locale locale) {
-    final List<String> parameterNames = new ArrayList<String>();
+    final List<String> parameterNames = new ArrayList<>();
     final String processedPattern = process(pattern, parameterNames);
     return new Template(processedPattern, parameterNames, locale);
   }
@@ -110,9 +110,9 @@ public class Template extends MessageFormat {
    * @return Pattern with named parameters substituted with ordinals
    */
   private static String process(String pattern, List<String> parameterNames) {
-    StringBuffer[] segments = new StringBuffer[4];
+    StringBuilder[] segments = new StringBuilder[4];
     for (int i = 0; i < segments.length; ++i) {
-      segments[i] = new StringBuffer();
+      segments[i] = new StringBuilder();
     }
     int part = 0;
     boolean inQuote = false;
@@ -184,7 +184,7 @@ public class Template extends MessageFormat {
    * @param parameterNames List of parameter names seen so far
    */
   private static void makeFormat(
-      StringBuffer[] segments,
+      StringBuilder[] segments,
       List<String> parameterNames) {
     final String parameterName = segments[1].toString();
     final int parameterOrdinal = parameterNames.size();

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/Unsafe.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/Unsafe.java b/core/src/main/java/org/apache/calcite/util/Unsafe.java
new file mode 100644
index 0000000..61805ab
--- /dev/null
+++ b/core/src/main/java/org/apache/calcite/util/Unsafe.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.util;
+
+import java.io.StringWriter;
+
+/**
+ * Contains methods that call JDK methods that the
+ * <a href="https://github.com/policeman-tools/forbidden-apis">forbidden
+ * APIs checker</a> does not approve of.
+ *
+ * <p>This class is excluded from the check, so methods called via this class
+ * will not fail the build.
+ */
+public class Unsafe {
+  private Unsafe() {}
+
+  /** Calls {@link System#exit}. */
+  public static void systemExit(int status) {
+    System.exit(status);
+  }
+
+  /** Calls {@link Object#notifyAll()}. */
+  public static void notifyAll(Object o) {
+    o.notifyAll();
+  }
+
+  /** Calls {@link Object#wait()}. */
+  public static void wait(Object o) throws InterruptedException {
+    o.wait();
+  }
+
+  /** Clears the contents of a {@link StringWriter}. */
+  public static void clear(StringWriter sw) {
+    // Included in this class because StringBuffer is banned.
+    sw.getBuffer().setLength(0);
+  }
+}
+
+// End Unsafe.java

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/Util.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/Util.java b/core/src/main/java/org/apache/calcite/util/Util.java
index 8d85ad9..24d9ab5 100644
--- a/core/src/main/java/org/apache/calcite/util/Util.java
+++ b/core/src/main/java/org/apache/calcite/util/Util.java
@@ -16,6 +16,7 @@
  */
 package org.apache.calcite.util;
 
+import org.apache.calcite.avatica.util.DateTimeUtils;
 import org.apache.calcite.avatica.util.Spaces;
 import org.apache.calcite.linq4j.Ord;
 import org.apache.calcite.runtime.CalciteException;
@@ -43,10 +44,16 @@ import org.slf4j.Logger;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
+import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.io.Reader;
@@ -60,6 +67,7 @@ import java.math.BigDecimal;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -70,6 +78,7 @@ import java.util.AbstractMap;
 import java.util.AbstractSet;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -619,7 +628,8 @@ public class Util {
    */
   @Deprecated // to be removed before 2.0
   public static String getFileTimestamp() {
-    SimpleDateFormat sdf = new SimpleDateFormat(FILE_TIMESTAMP_FORMAT);
+    SimpleDateFormat sdf =
+        new SimpleDateFormat(FILE_TIMESTAMP_FORMAT, Locale.ROOT);
     return sdf.format(new java.util.Date());
   }
 
@@ -1304,13 +1314,13 @@ public class Util {
    */
   public static String toPosix(TimeZone tz, boolean verbose) {
     StringBuilder buf = new StringBuilder();
-    buf.append(tz.getDisplayName(false, TimeZone.SHORT));
+    buf.append(tz.getDisplayName(false, TimeZone.SHORT, Locale.ROOT));
     appendPosixTime(buf, tz.getRawOffset());
     final int dstSavings = tz.getDSTSavings();
     if (dstSavings == 0) {
       return buf.toString();
     }
-    buf.append(tz.getDisplayName(true, TimeZone.SHORT));
+    buf.append(tz.getDisplayName(true, TimeZone.SHORT, Locale.ROOT));
     if (verbose || (dstSavings != 3600000)) {
       // POSIX allows us to omit DST offset if it is 1:00:00
       appendPosixTime(buf, dstSavings);
@@ -2368,6 +2378,48 @@ public class Util {
     return builder.build();
   }
 
+  /** Creates a {@link PrintWriter} to a given output stream using UTF-8
+   * character set.
+   *
+   * <p>Does not use the default character set. */
+  public static PrintWriter printWriter(OutputStream out) {
+    return new PrintWriter(
+        new BufferedWriter(
+            new OutputStreamWriter(out, StandardCharsets.UTF_8)));
+  }
+
+  /** Creates a {@link PrintWriter} to a given file using UTF-8
+   * character set.
+   *
+   * <p>Does not use the default character set. */
+  public static PrintWriter printWriter(File file)
+      throws FileNotFoundException {
+    return printWriter(new FileOutputStream(file));
+  }
+
+  /** Creates a {@link BufferedReader} to a given input stream using UTF-8
+   * character set.
+   *
+   * <p>Does not use the default character set. */
+  public static BufferedReader reader(InputStream in) {
+    return new BufferedReader(
+        new InputStreamReader(in, StandardCharsets.UTF_8));
+  }
+
+  /** Creates a {@link BufferedReader} to read a given file using UTF-8
+   * character set.
+   *
+   * <p>Does not use the default character set. */
+  public static BufferedReader reader(File file) throws FileNotFoundException {
+    return reader(new FileInputStream(file));
+  }
+
+  /** Creates a {@link Calendar} in the GMT time zone and root locale.
+   * Does not use the time zone or locale. */
+  public static Calendar calendar() {
+    return Calendar.getInstance(DateTimeUtils.GMT_ZONE, Locale.ROOT);
+  }
+
   //~ Inner Classes ----------------------------------------------------------
 
   /**

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/ZonelessDatetime.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/ZonelessDatetime.java b/core/src/main/java/org/apache/calcite/util/ZonelessDatetime.java
index 13e956b..ab311e7 100644
--- a/core/src/main/java/org/apache/calcite/util/ZonelessDatetime.java
+++ b/core/src/main/java/org/apache/calcite/util/ZonelessDatetime.java
@@ -21,6 +21,7 @@ import org.apache.calcite.avatica.util.DateTimeUtils;
 import java.io.Serializable;
 import java.text.DateFormat;
 import java.util.Calendar;
+import java.util.Locale;
 import java.util.TimeZone;
 
 /**
@@ -171,7 +172,7 @@ public abstract class ZonelessDatetime implements BasicDatetime, Serializable {
    */
   protected Calendar getCalendar(TimeZone zone) {
     if (tempCal == null) {
-      tempCal = Calendar.getInstance(zone);
+      tempCal = Calendar.getInstance(zone, Locale.ROOT);
     } else {
       tempCal.setTimeZone(zone);
     }

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java b/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java
index af170d9..1ac6a39 100644
--- a/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java
+++ b/core/src/main/java/org/apache/calcite/util/javac/JaninoCompiler.java
@@ -24,6 +24,7 @@ import org.codehaus.janino.util.resource.ResourceFinder;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -67,7 +68,7 @@ public class JaninoCompiler implements JavaCompiler {
     Map<String, byte[]> sourceMap = new HashMap<String, byte[]>();
     sourceMap.put(
         ClassFile.getSourceResourceName(args.fullClassName),
-        args.source.getBytes());
+        args.source.getBytes(StandardCharsets.UTF_8));
     MapResourceFinder sourceFinder = new MapResourceFinder(sourceMap);
 
     classLoader =

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/main/java/org/apache/calcite/util/trace/CalciteTimingTracer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/util/trace/CalciteTimingTracer.java b/core/src/main/java/org/apache/calcite/util/trace/CalciteTimingTracer.java
index 792ab79..07ada81 100644
--- a/core/src/main/java/org/apache/calcite/util/trace/CalciteTimingTracer.java
+++ b/core/src/main/java/org/apache/calcite/util/trace/CalciteTimingTracer.java
@@ -16,6 +16,8 @@
  */
 package org.apache.calcite.util.trace;
 
+import org.apache.calcite.util.NumberUtil;
+
 import org.slf4j.Logger;
 
 import java.text.DecimalFormat;
@@ -28,7 +30,7 @@ public class CalciteTimingTracer {
   //~ Static fields/initializers ---------------------------------------------
 
   private static final DecimalFormat DECIMAL_FORMAT =
-      new DecimalFormat("###,###,###,###,###");
+      NumberUtil.decimalFormat("###,###,###,###,###");
 
   //~ Instance fields --------------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java b/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java
index 4578822..e08e3c0 100644
--- a/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java
+++ b/core/src/test/java/org/apache/calcite/jdbc/CalciteRemoteDriverTest.java
@@ -30,6 +30,7 @@ import org.apache.calcite.prepare.CalcitePrepareImpl;
 import org.apache.calcite.test.CalciteAssert;
 import org.apache.calcite.test.JdbcFrontLinqBackTest;
 import org.apache.calcite.test.JdbcTest;
+import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
@@ -42,11 +43,12 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.sql.Array;
 import java.sql.Blob;
 import java.sql.Clob;
@@ -70,6 +72,7 @@ import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import static org.hamcrest.CoreMatchers.equalTo;
@@ -85,9 +88,9 @@ import static org.junit.Assert.assertThat;
 public class CalciteRemoteDriverTest {
   public static final String LJS = Factory2.class.getName();
 
-  private final PrintStream out =
-      CalcitePrepareImpl.DEBUG ? System.out
-          : new PrintStream(new ByteArrayOutputStream());
+  private final PrintWriter out =
+      CalcitePrepareImpl.DEBUG ? Util.printWriter(System.out)
+          : new PrintWriter(new StringWriter());
 
   private static final CalciteAssert.ConnectionFactory
   REMOTE_CONNECTION_FACTORY =
@@ -429,9 +432,10 @@ public class CalciteRemoteDriverTest {
       SqlType.NCHAR, SqlType.NVARCHAR, SqlType.LONGNVARCHAR, SqlType.NCLOB,
       SqlType.SQLXML
     };
-    final PrintStream out =
-        CalcitePrepareImpl.DEBUG ? System.out
-            : new PrintStream(new ByteArrayOutputStream());
+    final PrintWriter out =
+        CalcitePrepareImpl.DEBUG
+            ? Util.printWriter(System.out)
+            : new PrintWriter(new StringWriter());
     for (SqlType.Method row : SqlType.Method.values()) {
       out.print(pad(row.methodName));
       for (SqlType column : columns) {
@@ -632,7 +636,7 @@ public class CalciteRemoteDriverTest {
           // string
           "", "foo", " foo! Baz ",
           // byte[]
-          new byte[0], "hello".getBytes());
+          new byte[0], "hello".getBytes(StandardCharsets.UTF_8));
 
   private static List<Object> values(Class clazz) {
     final List<Object> list = Lists.newArrayList();
@@ -659,7 +663,7 @@ public class CalciteRemoteDriverTest {
     }
     if (clazz == byte[].class) {
       if (o instanceof String) {
-        return ((String) o).getBytes();
+        return ((String) o).getBytes(StandardCharsets.UTF_8);
       }
     }
     if (clazz == Timestamp.class) {
@@ -679,12 +683,15 @@ public class CalciteRemoteDriverTest {
     }
     if (clazz == java.util.Date.class) {
       if (o instanceof String) {
-        return DateFormat.getInstance().parse((String) o);
+        final DateFormat dateFormat =
+            DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
+                Locale.ROOT);
+        return dateFormat.parse((String) o);
       }
     }
     if (clazz == Calendar.class) {
       if (o instanceof String) {
-        return Calendar.getInstance(); // TODO:
+        return Util.calendar(); // TODO:
       }
     }
     if (o instanceof Boolean) {

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java b/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
index cd453cd..3a1227f 100644
--- a/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
+++ b/core/src/test/java/org/apache/calcite/rex/RexExecutorTest.java
@@ -19,7 +19,6 @@ package org.apache.calcite.rex;
 import org.apache.calcite.DataContext;
 import org.apache.calcite.adapter.java.JavaTypeFactory;
 import org.apache.calcite.avatica.util.ByteString;
-import org.apache.calcite.avatica.util.DateTimeUtils;
 import org.apache.calcite.linq4j.QueryProvider;
 import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelOptSchema;
@@ -38,6 +37,7 @@ import org.apache.calcite.sql.type.ReturnTypes;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.tools.Frameworks;
 import org.apache.calcite.util.NlsString;
+import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
 import com.google.common.collect.ImmutableList;
@@ -159,7 +159,7 @@ public class RexExecutorTest {
     checkConstant(true,
         new Function<RexBuilder, RexNode>() {
           public RexNode apply(RexBuilder rexBuilder) {
-            Calendar calendar = Calendar.getInstance(DateTimeUtils.GMT_ZONE);
+            Calendar calendar = Util.calendar();
             return rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN_OR_EQUAL,
                 rexBuilder.makeDateLiteral(calendar),
                 rexBuilder.makeDateLiteral(calendar));
@@ -169,7 +169,7 @@ public class RexExecutorTest {
     checkConstant(false,
         new Function<RexBuilder, RexNode>() {
           public RexNode apply(RexBuilder rexBuilder) {
-            Calendar calendar = Calendar.getInstance(DateTimeUtils.GMT_ZONE);
+            Calendar calendar = Util.calendar();
             return rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN,
                 rexBuilder.makeDateLiteral(calendar),
                 rexBuilder.makeDateLiteral(calendar));

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
index 54fce65..9c47a4f 100644
--- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -46,7 +46,6 @@ import org.junit.Test;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.net.URL;
@@ -6595,8 +6594,9 @@ public class SqlParserTest {
     for (Map.Entry<String, List<String>> intervalGroup : tsi.entrySet()) {
       for (String function : functions) {
         for (String interval : intervalGroup.getValue()) {
-          checkExp(String.format(function, interval, ""),
-              String.format(function, intervalGroup.getKey(), "`").toUpperCase());
+          checkExp(String.format(Locale.ROOT, function, interval, ""),
+              String.format(Locale.ROOT, function, intervalGroup.getKey(), "`")
+                  .toUpperCase(Locale.ROOT));
         }
       }
     }
@@ -6819,9 +6819,9 @@ public class SqlParserTest {
     final File inFile = new File(base, "site/_docs/reference.md");
     final File outFile = new File(base, "core/target/surefire/reference.md");
     outFile.getParentFile().mkdirs();
-    try (BufferedReader r = new BufferedReader(new FileReader(inFile));
+    try (BufferedReader r = Util.reader(inFile);
          FileOutputStream fos = new FileOutputStream(outFile);
-         PrintWriter w = new PrintWriter(fos)) {
+         PrintWriter w = Util.printWriter(outFile)) {
       String line;
       int stage = 0;
       while ((line = r.readLine()) != null) {

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
index 95000f6..1fd1933 100644
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/test/SqlOperatorBaseTest.java
@@ -51,6 +51,7 @@ import org.apache.calcite.test.SqlLimitsTest;
 import org.apache.calcite.util.Bug;
 import org.apache.calcite.util.Holder;
 import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
 
 import com.google.common.base.Function;
 import com.google.common.base.Throwables;
@@ -72,6 +73,7 @@ import java.util.Calendar;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 import java.util.TimeZone;
 import java.util.regex.Pattern;
 
@@ -1202,7 +1204,7 @@ public abstract class SqlOperatorBaseTest {
     // is guaranteed to be good for at least 2 minutes, which should give
     // us time to run the rest of the tests.
     final String today =
-        new SimpleDateFormat("yyyy-MM-dd").format(
+        new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT).format(
             getCalendarNotTooNear(Calendar.DAY_OF_MONTH).getTime());
 
     tester.checkScalar(
@@ -1384,7 +1386,7 @@ public abstract class SqlOperatorBaseTest {
    * @return calendar
    */
   protected static Calendar getCalendarNotTooNear(int timeUnit) {
-    final Calendar cal = Calendar.getInstance();
+    final Calendar cal = Util.calendar();
     while (true) {
       cal.setTimeInMillis(System.currentTimeMillis());
       try {
@@ -4517,7 +4519,7 @@ public abstract class SqlOperatorBaseTest {
         public void close() {}
       };
     } else {
-      calendar = Calendar.getInstance();
+      calendar = Util.calendar();
       calendar.set(Calendar.YEAR, 2014);
       calendar.set(Calendar.MONTH, 8);
       calendar.set(Calendar.DATE, 7);
@@ -4535,7 +4537,7 @@ public abstract class SqlOperatorBaseTest {
           });
     }
 
-    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:");
+    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:", Locale.ROOT);
     sdf.setTimeZone(tz);
     return Pair.of(sdf.format(calendar.getTime()), closeable);
   }
@@ -6662,7 +6664,7 @@ public abstract class SqlOperatorBaseTest {
       case VARCHAR:
         return SqlLiteral.createCharString(value.toString(), SqlParserPos.ZERO);
       case TIMESTAMP:
-        Calendar calendar = Calendar.getInstance();
+        Calendar calendar = Util.calendar();
         calendar.setTimeInMillis((Long) value);
         return SqlLiteral.createTimestamp(calendar, type.getPrecision(),
             SqlParserPos.ZERO);

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/test/java/org/apache/calcite/sql/validate/SqlValidatorUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/validate/SqlValidatorUtilTest.java b/core/src/test/java/org/apache/calcite/sql/validate/SqlValidatorUtilTest.java
index 87de5f5..5fe474f 100644
--- a/core/src/test/java/org/apache/calcite/sql/validate/SqlValidatorUtilTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/validate/SqlValidatorUtilTest.java
@@ -22,6 +22,7 @@ import org.junit.Test;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 
 import static org.hamcrest.CoreMatchers.anyOf;
 import static org.hamcrest.CoreMatchers.is;
@@ -48,14 +49,15 @@ public class SqlValidatorUtilTest {
     // Make sure each name is unique
     List<String> copyResultList  = new ArrayList<>(resultList.size());
     for (String result : resultList) {
-      copyResultList.add(result.toLowerCase());
+      copyResultList.add(result.toLowerCase(Locale.ROOT));
     }
 
     for (String result : resultList) {
-      assertThat(copyResultList.contains(result.toLowerCase()), is(true));
-      copyResultList.remove(result.toLowerCase());
+      final String lowerResult = result.toLowerCase(Locale.ROOT);
+      assertThat(copyResultList.contains(lowerResult), is(true));
+      copyResultList.remove(lowerResult);
       if (!caseSensitive) {
-        assertThat(copyResultList.contains(result.toLowerCase()), is(false));
+        assertThat(copyResultList.contains(lowerResult), is(false));
       }
     }
     assertThat(copyResultList.size(), is(0));

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
index fad0812..dd7168c 100644
--- a/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
+++ b/core/src/test/java/org/apache/calcite/test/CalciteAssert.java
@@ -77,6 +77,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Properties;
@@ -114,7 +115,7 @@ public class CalciteAssert {
   public static final DatabaseInstance DB =
       DatabaseInstance.valueOf(
           Util.first(System.getProperty("calcite.test.db"), "HSQLDB")
-              .toUpperCase());
+              .toUpperCase(Locale.ROOT));
 
   /** Whether to enable slow tests. Default is false. */
   public static final boolean ENABLE_SLOW =
@@ -125,11 +126,12 @@ public class CalciteAssert {
   private static final DateFormat UTC_TIMESTAMP_FORMAT;
   static {
     final TimeZone utc = DateTimeUtils.GMT_ZONE;
-    UTC_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
+    UTC_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
     UTC_DATE_FORMAT.setTimeZone(utc);
-    UTC_TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");
+    UTC_TIME_FORMAT = new SimpleDateFormat("HH:mm:ss", Locale.ROOT);
     UTC_TIME_FORMAT.setTimeZone(utc);
-    UTC_TIMESTAMP_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+    UTC_TIMESTAMP_FORMAT =
+        new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);
     UTC_TIMESTAMP_FORMAT.setTimeZone(utc);
   }
 
@@ -1418,7 +1420,8 @@ public class CalciteAssert {
       boolean save = materializationsEnabled;
       try {
         materializationsEnabled = false;
-        final boolean ordered = sql.toUpperCase().contains("ORDER BY");
+        final boolean ordered =
+            sql.toUpperCase(Locale.ROOT).contains("ORDER BY");
         final Function<ResultSet, Void> checker = consistentResult(ordered);
         returns(checker);
         materializationsEnabled = true;

http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/75152c5b/core/src/test/java/org/apache/calcite/test/DiffRepository.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/DiffRepository.java b/core/src/test/java/org/apache/calcite/test/DiffRepository.java
index 622c526..ee48d9d 100644
--- a/core/src/test/java/org/apache/calcite/test/DiffRepository.java
+++ b/core/src/test/java/org/apache/calcite/test/DiffRepository.java
@@ -34,7 +34,6 @@ import org.w3c.dom.Text;
 import org.xml.sax.SAXException;
 
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
 import java.net.URL;
@@ -526,7 +525,7 @@ public class DiffRepository {
     try {
       boolean b = logFile.getParentFile().mkdirs();
       Util.discard(b);
-      try (FileWriter w = new FileWriter(logFile)) {
+      try (Writer w = Util.printWriter(logFile)) {
         write(doc, w, indent);
       }
     } catch (IOException e) {


Mime
View raw message