001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.util;
019
020import java.util.HashSet;
021import java.util.Set;
022import org.apache.yetus.audience.InterfaceAudience;
023import org.apache.yetus.audience.InterfaceStability;
024
025/**
026 * Utility class to get and check the current JVM version.
027 */
028@InterfaceAudience.Private
029@InterfaceStability.Stable
030public abstract class JvmVersion {
031  private static Set<String> BAD_JVM_VERSIONS = new HashSet<>();
032  static {
033    BAD_JVM_VERSIONS.add("1.6.0_18");
034  }
035
036  /**
037   * Return true if the current JVM version is known to be unstable with HBase.
038   */
039  public static boolean isBadJvmVersion() {
040    String version = System.getProperty("java.version");
041    return version != null && BAD_JVM_VERSIONS.contains(version);
042  }
043
044  /**
045   * Return the current JVM version information.
046   */
047  public static String getVersion() {
048    return System.getProperty("java.vm.vendor", "UNKNOWN_VM_VENDOR") + ' '
049      + System.getProperty("java.version", "UNKNOWN_JAVA_VERSION") + '-'
050      + System.getProperty("java.vm.version", "UNKNOWN_VM_VERSION");
051  }
052}