Skip to content

Commit

Permalink
First round of Coverity uncovered issues.
Browse files Browse the repository at this point in the history
Signed-off-by: Madhan Neethiraj <[email protected]>
  • Loading branch information
Abhay Kulkarni authored and mneethiraj committed Mar 25, 2015
1 parent 59304ba commit cb4eb54
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RangerConfiguration extends Configuration {

private static final Logger LOG = Logger.getLogger(RangerConfiguration.class) ;

private static RangerConfiguration config = null;
private static volatile RangerConfiguration config = null;

private RangerConfiguration() {
super(false) ;
Expand Down Expand Up @@ -88,15 +88,16 @@ private void addResourceIfReadable(String aResourceName) {


public static RangerConfiguration getInstance() {
if (config == null) {
RangerConfiguration result = config;
if (result == null) {
synchronized (RangerConfiguration.class) {
RangerConfiguration temp = config;
if (temp == null) {
config = new RangerConfiguration();
result = config;
if (result == null) {
config = result = new RangerConfiguration();
}
}
}
return config;
return result;
}

public void initAudit(String appType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class RangerRESTClient {
private String mTrustStoreType = null;

private Gson gsonBuilder = null;
private Client client = null;
private volatile Client client = null;

public RangerRESTClient() {
this(RangerConfiguration.getInstance().get(RANGER_PROP_POLICYMGR_URL),
Expand Down Expand Up @@ -150,15 +150,18 @@ public <T> T fromJson(String json, Class<T> cls) {
}

public Client getClient() {
if(client == null) {
// result saves on access time when client is built at the time of the call
Client result = client;
if(result == null) {
synchronized(this) {
if(client == null) {
client = buildClient();
result = client;
if(result == null) {
client = result = buildClient();
}
}
}

return client;
return result;
}

private Client buildClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ public class RangerCredentialProvider {

private static Log LOG = LogFactory.getLog(RangerCredentialProvider.class);

private static RangerCredentialProvider me = null;
private static volatile RangerCredentialProvider me = null;


public static RangerCredentialProvider getInstance() {
if ( me == null) {
RangerCredentialProvider result = me;
if ( result == null) {
synchronized(RangerCredentialProvider.class) {
RangerCredentialProvider temp = me;
if ( temp == null){
me = new RangerCredentialProvider();
result = me;
if ( result == null){
me = result = new RangerCredentialProvider();
}
}
}
return me;
return result;
}

public char[] getCredentialString(String url, String alias) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,23 @@ public class Crypt {
private static final String CIPHER_ALGO = "AES/CBC/PKCS5Padding";
private static final String CIPHER_INIT_ALGO = "AES";

private static Crypt me = null ;
private static volatile Crypt me = null ;

private Cipher encrypter = null;
private Cipher descrypter = null;


public static Crypt getInstance() {
if (me == null) {
Crypt result = me;
if (result == null) {
synchronized (Crypt.class) {
Crypt other = me ;
if (other == null) {
me = new Crypt() ;
result = me ;
if (result == null) {
me = result = new Crypt() ;
}
}
}
return me ;
return result ;
}

private Crypt() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ public byte[] transform(ClassLoader aClassLoader, String aClassName, Class<?> aC
byte[] ret = aClassFileBuffer;

if (aClassName.equals("org/apache/hadoop/hdfs/server/namenode/FSPermissionChecker")) {
if (transformedClassByteCode == null) {
byte[] result = transformedClassByteCode;
if (result == null) {

byte[] injectedClassCode = injectFSPermissionCheckerHooks(aClassLoader, aClassName, aClassBeingRedefined, aProtectionDomain, aClassFileBuffer);

if(injectedClassCode != null) {
if(transformedClassByteCode == null) {
synchronized(HadoopAuthClassTransformer.class) {
byte[] temp = transformedClassByteCode;
if (temp == null) {
transformedClassByteCode = injectedClassCode;
}
}
}
}
synchronized (HadoopAuthClassTransformer.class) {
result = transformedClassByteCode;
if (result == null) {
transformedClassByteCode = result = injectedClassCode;
}
}
}
}

if(transformedClassByteCode != null) {
ret = transformedClassByteCode;
if(result != null) {
ret = result;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,29 @@ public List<String> getTblList(String tableNameMatching, List<String> dbList, Li
}
finally {
close(stat) ;
stat = null;
}

sql = "show tables " ;
if (tableNameMatching != null && ! tableNameMatching.isEmpty()) {
sql = sql + " like \"" + tableNameMatching + "\"" ;
}
stat = con.createStatement() ;
rs = stat.executeQuery(sql) ;
while (rs.next()) {
String tblName = rs.getString(1);
if ( tblList != null && tblList.contains(tblName)) {
continue;
}
ret.add(tblName);
}
try {
stat = con.createStatement();
rs = stat.executeQuery(sql);
while (rs.next()) {
String tblName = rs.getString(1);
if (tblList != null && tblList.contains(tblName)) {
continue;
}
ret.add(tblName);
}
} finally {
close(rs);
close(stat);
rs = null;
stat = null;
}
}
}
} catch (SQLTimeoutException sqlt) {
Expand All @@ -227,9 +235,6 @@ public List<String> getTblList(String tableNameMatching, List<String> dbList, Li
LOG.debug("<== HiveClient.getTblList() Error : " + sqle) ;
}
throw hdpException;
} finally {
close(rs) ;
close(stat) ;
}

}
Expand Down
10 changes: 10 additions & 0 deletions jisql/src/main/java/org/apache/util/sql/Jisql.java
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,16 @@ public void doIsql() throws SQLException {
// Ignore IOE when closing streams
}
}
if (statement != null) {
try {
if (!statement.isClosed()) {
statement.close();
}

} catch (SQLException sqle) {
// Ignore
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,25 @@

public class RangerRESTAPIFilter extends LoggingFilter {
Logger logger = Logger.getLogger(RangerRESTAPIFilter.class);
static boolean initDone = false;
static volatile boolean initDone = false;

boolean logStdOut = true;
HashMap<String, String> regexPathMap = new HashMap<String, String>();
HashMap<String, Pattern> regexPatternMap = new HashMap<String, Pattern>();
List<String> regexList = new ArrayList<String>();
List<String> loggedRestPathErrors = new ArrayList<String>();
private final Object lock = new Object();

void init() {
if (initDone) {
return;
}
synchronized (lock) {
synchronized (RangerRESTAPIFilter.class) {
if (initDone) {
return;
}

logStdOut = PropertiesUtil.getBooleanProperty(
"xa.restapi.log.enabled", initDone);
"xa.restapi.log.enabled", false);

// Build hash map
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,19 @@ public class UserGroupSyncConfig {

private Properties prop = new Properties() ;

private static UserGroupSyncConfig me = null ;
private static volatile UserGroupSyncConfig me = null ;

public static UserGroupSyncConfig getInstance() {
if (me == null) {
UserGroupSyncConfig result = me;
if (result == null) {
synchronized(UserGroupSyncConfig.class) {
UserGroupSyncConfig temp = me ;
if (temp == null) {
me = new UserGroupSyncConfig() ;
result = me ;
if (result == null) {
me = result = new UserGroupSyncConfig() ;
}
}
}
return me ;
return result ;
}


Expand Down

0 comments on commit cb4eb54

Please sign in to comment.