auphong2707/dl4se-code-review-dataset huggingface dataset:
Source:
public boolean isLoggedIn() { Token accessToken = getAccessToken(); START return (accessToken != null) ? true : false; END } this can be simplified by: ``` return accessToken != null ```

Target:
public boolean isLoggedIn() { Token accessToken = getAccessToken(); return accessToken != null; }
Source:
private void animateViewTransitions() { fadeOutMotto(); delayButtonHandler = new Handler(); delayButtonHandler.postDelayed(new Runnable() { @Override public void run() { setMottoInvisible(); fadeInLoginView(); } } START , 2000); END } why on separate line?

Target:
private void animateViewTransitions() { fadeOutMotto(); delayButtonHandler = new Handler(); delayButtonHandler.postDelayed(new Runnable() { @Override public void run() { fadeInLoginView(); } }, 2000); }
Source:
protected void onServiceConnectionLost(int errorCode) { Logger.e(TAG + "onServiceConectionLost for peer = " + mConnectionId + "error code =" + errorCode); START if (GearAgentService.getConnection() != null) { END GearAgentService.setConnection(null); } } Is this if statement needed? Seems ok to just set to null.

Target:
protected void onServiceConnectionLost(int errorCode) { Logger.e(TAG + "onServiceConectionLost for peer = " + mConnectionId + "error code =" + errorCode); GearAgentService.setConnection(null); }
Source:
public void onCreate_debugViewShouldBeVisible() throws Exception { START enableDebugMode(Robolectric.application.getApplicationContext()); END BaseActivity act = TestHelper.initBaseActivity(); assertThat(act.findViewById(R.id.debugging)).isVisible(); } FYI `getApplicationContext()` is generally not needed unless you need to access the application from a non-application context. Here it just returns the same instance as `application` under the hood.

Target:
public void onCreate_debugViewShouldBeVisible() throws Exception { enableDebugMode(Robolectric.application); BaseActivity act = TestHelper.initBaseActivity(); assertThat(act.findViewById(R.id.debugging)).isVisible(); }
Source:
public AutoCompleteAdapter(Context context, BaseActivity act, String[] columns) { super(context, new MatrixCursor(columns), 0); this.context = context; this.app = (MapzenApplication) act.getApplication(); START this.act = act; END } Field act does not exist in AutoCompleteAdapter?

Target:
public AutoCompleteAdapter(Context context, BaseActivity act, String[] columns) { super(context, new MatrixCursor(columns), 0); this.context = context; this.app = (MapzenApplication) act.getApplication(); }
Source:
private void initResultsFragment() { pagerResultsFragment = new PagerResultsFragment(); pagerResultsFragment.setAct(this); START pagerResultsFragment.setApp(app); END pagerResultsFragment.setAdapter(new SearchViewAdapter(this, getSupportFragmentManager())); // TODO remove fugly HACK pagerResultsFragment.setMapFragment(mapFragment); } This shouldn't be necessary. The fragment can get the app from the activity.

Target:
private void initResultsFragment() { pagerResultsFragment = new PagerResultsFragment(); pagerResultsFragment.setAct(this); pagerResultsFragment.setAdapter(new SearchViewAdapter(this, getSupportFragmentManager())); // TODO remove fugly HACK pagerResultsFragment.setMapFragment(mapFragment); }
Source:
public ExtensionBootstrapper(final ServletContext context, final Configuration configuration) { this.configuration = configuration; this.context = context; START this.context.setAttribute(ExtensionContext.class.getName(), ExtensionController.getInstance()); END ExtensionController.getInstance().init(this.context); } do we need this anylonger?

Target:
public ExtensionBootstrapper(final ServletContext context, final Configuration configuration) { this.configuration = configuration; this.context = context; ExtensionController.getInstance().init(this.context); }
Source:
public static boolean isValidEmailFormat ( String email ) { boolean isValid = false; try { InternetAddress emailAddress = new InternetAddress(email); emailAddress.validate(); isValid = true; } catch (AddressException ex) { isValid = false; START logger.error("Email " + email + " is invalid"); END } return isValid; } i would change the log level here to `warn` (if not `info`). (`error` is usually reserved for severe issues that affect the application health. on the other hand, this is very much a normal operation of handling invalid user input - `info` sounds like a better fit imho)

Target:
public static boolean isValidEmailFormat ( String email ) { boolean isValid = false; try { InternetAddress emailAddress = new InternetAddress(email); emailAddress.validate(); isValid = true; } catch (AddressException ex) { isValid = false; logger.warn("Email " + email + " is invalid"); } return isValid; }
Source:
private void onReceiveTimeout(ReceiveTimeout message, ActorRef self, ActorRef sender) throws Exception { if (logger.isInfoEnabled()) { logger.info("Conference Received Timeout, will stop conference now."); } START onStopConference(new StopConference(SUPER_ADMIN_ACCOUNT_SID), self, sender); END } @maria-farooq Maybe we should differentiate the StopConference initiated by SuperAdmin and the one initiated by the timer. This is just an idea, not sure about the implementation but I think if it sounds feasible to you we should investigate it

Target:
private void onReceiveTimeout(ReceiveTimeout message, ActorRef self, ActorRef sender) throws Exception { if (logger.isInfoEnabled()) { logger.info("Conference Received Timeout, will stop conference now."); } onStopConference(new StopConference(), self, sender); }
Source:
public MockMediaGateway() { super(); system = context().system(); connectionToEndpointMap = new ConcurrentHashMap<ActorRef, ActorRef>(); START connEndpointMap = new ConcurrentHashMap<String, String>(); END } considering this is Actor state, and concurrency should be already solved by Actor model, is there any particular intention on using ConcurrentHashMap??

Target:
public MockMediaGateway() { super(); system = context().system(); connEndpointMap = new ConcurrentHashMap<String, String>(); }
Source:
public DeleteBulkFactory(Settings settings, MetadataExtractor metaExtractor, EsMajorVersion version) { // we only want a specific serializer for this particular bulk factory START super(settings.copy().setSerializerValueWriterClassName(NoDataWriter.class.getName()), metaExtractor, version); END } Also not required if we use a new implementation of `BulkCommand`

Target:
public DeleteBulkFactory(Settings settings, MetadataExtractor metaExtractor, EsMajorVersion version) { super(settings, metaExtractor, version); }
Source:
public BufferedRestClient(Settings settings) { this.settings = settings; this.client = new RestClient(settings); String tempIndex = settings.getTargetResource(); if (tempIndex == null) { tempIndex = ""; } this.index = tempIndex; this.resource = new Resource(index); START if (this.settings.getParentIdPath() != null) END enableParentChildIndex = true; else enableParentChildIndex = false; trace = log.isTraceEnabled(); } enableParentChildIndex = ( this.settings.getParentIdPath() != null ) ? true: false;

Target:
public BufferedRestClient(Settings settings) { this.settings = settings; this.client = new RestClient(settings); String tempIndex = settings.getTargetResource(); if (tempIndex == null) { tempIndex = ""; } this.index = tempIndex; this.resource = new Resource(index); enableParentChildIndex = (this.settings.getParentIdPath() != null); trace = log.isTraceEnabled(); }
Source:
public void shutdownAndAwaitTerminationWithTimeoutExpireTest() throws InterruptedException { SingleThreadScheduler sts = new SingleThreadScheduler(); executeTestRunnables(sts, 1000 * 10); long start = Clock.accurateForwardProgressingMillis(); assertFalse(sts.shutdownAndAwaitTermination(DELAY_TIME)); START System.out.println(Clock.accurateForwardProgressingMillis() - start); END assertTrue(Clock.accurateForwardProgressingMillis() - start >= (DELAY_TIME - ALLOWED_VARIANCE)); } Please remove System.out calls

Target:
public void shutdownAndAwaitTerminationWithTimeoutExpireTest() throws InterruptedException { SingleThreadScheduler sts = new SingleThreadScheduler(); executeTestRunnables(sts, 1000 * 10); long start = Clock.accurateForwardProgressingMillis(); assertFalse(sts.shutdownAndAwaitTermination(DELAY_TIME)); assertTrue(Clock.accurateForwardProgressingMillis() - start >= (DELAY_TIME - ALLOWED_VARIANCE)); }
Source:
START public void setFailure(Throwable failure) { END if (failure == null) { failure = new Exception(); } synchronized (resultLock) { this.failure = failure; if (! setDone()) { return; } } // call outside of lock listenerHelper.callListeners(); } should probably change the overloaded variable name failure here.

Target:
public void setFailure(Throwable failure) { synchronized (resultLock) { if (! setDone()) { return; } if (failure == null) { failure = new Exception(); } this.failure = failure; } // call outside of lock listenerHelper.callListeners(); }
Source:
START public QueueSet getQueueSet(TaskPriority priority) { END switch (priority) { case High: return highPriorityQueueSet; case Low: return lowPriorityQueueSet; default: throw new UnsupportedOperationException(); } } this might be quicker as an if/else if/else.

Target:
public QueueSet getQueueSet(TaskPriority priority) { if (priority == TaskPriority.High) { return highPriorityQueueSet; } else { return lowPriorityQueueSet; } }
Source:
public void stopAndDrainQueueInto(List<Runnable> removedTasks) { stopIfRunning(); START synchronized (executeQueueRemoveLock) { END clearQueue(executeQueue, removedTasks); } synchronized (scheduleQueue.getModificationLock()) { clearQueue(scheduleQueue, removedTasks); } } does locking here really buy us anything? We are not locking when we .add on this queue so I would not think it would matter.

Target:
public void stopAndDrainQueueInto(List<Runnable> removedTasks) { stopIfRunning(); clearQueue(executeQueue, removedTasks); synchronized (scheduleQueue.getModificationLock()) { clearQueue(scheduleQueue, removedTasks); } }
Source:
START public String getBearerToken(HttpServletRequest request) { END String authorization = request.getHeader("Authorization"); if (authorization == null) { throw new IllegalArgumentException("No access_token submitted!"); } return authorization.substring("Bearer ".length(), authorization.length()); } shouldn't this method be static? it seems to me like an ordinary utility function. are there any reasons you have to manage a singleton instance of this class with spring?

Target:
public static String getBearerToken(HttpServletRequest request) { String authorization = request.getHeader("Authorization"); if (authorization == null) { throw new IllegalArgumentException("No access_token submitted!"); } return authorization.substring("Bearer ".length(), authorization.length()); }
Source:
public void addGame(@NotNull Game game) { GamePanel panel = new GamePanel(getGlassPane(), game); START if(mTabbedPane.getTabCount() != 0) { END mTabbedPane.addTab(game.getGameType() + mTabbedPane.getTabCount(), panel); } else{ mTabbedPane.addTab(game.getGameType(), panel); } mTabbedPane.setSelectedComponent(panel); mCardLayout.show(mCardPanel, KEY_TABS); } We don't need this change, and even if we decide we want it, it needs to be in a separate commit

Target:
public void addGame(@NotNull Game game) { GamePanel panel = new GamePanel(getGlassPane(), game); mTabbedPane.addTab(game.getGameType() + mTabbedPane.getTabCount(), panel); mTabbedPane.setSelectedComponent(panel); mCardLayout.show(mCardPanel, KEY_TABS); }
Source:
START public TaskScheduler resolveTaskScheduler() { END return resolveSchedulerBean(TaskScheduler.class); } Can we make this package private instead?

Target:
TaskScheduler resolveTaskScheduler() { return resolveSchedulerBean(TaskScheduler.class); }
Source:
START public void clearKey(String tabName, String key) { END Map<String, Object> tab = getTab(tabName); tab.remove(key); } this only needs to be package visible

Target:
void clearKey(String tabName, String key) { Map<String, Object> tab = getTab(tabName); tab.remove(key); }
Source:
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { START return context.getClassLoader().getResource("org/springframework/web/servlet") != null; END } `context.getClassLoader()` can return null

Target:
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { return context.getClassLoader() != null && context.getClassLoader().getResource("org/springframework/web/servlet") != null; }
Source:
public String handledTypeMismatchException() { try { throw new TypeMismatchException("Test", String.class); } catch (TypeMismatchException ex) { bugsnag.notify(ex); } START return "The exception was handled"; END } Are these `return`s used anywhere? If not, might as well make the method `void`. Applies throughout.

Target:
public void handledTypeMismatchException() { try { throw new TypeMismatchException("Test", String.class); } catch (TypeMismatchException ex) { bugsnag.notify(ex); } }
Source:
Configuration(String apiKey) { this.apiKey = apiKey; // Add built-in callbacks addCallback(new AppCallback(this)); addCallback(new DeviceCallback()); DeviceCallback.initializeCache(); if (ServletCallback.isAvailable()) { addCallback(new ServletCallback()); } START sessionDelivery = new AsyncHttpDelivery(); END ((HttpDelivery) sessionDelivery).setEndpoint("https://sessions.bugsnag.com"); } Any reason you aren't initializing this at declaration time?

Target:
Configuration(String apiKey) { this.apiKey = apiKey; // Add built-in callbacks addCallback(new AppCallback(this)); addCallback(new DeviceCallback()); DeviceCallback.initializeCache(); if (ServletCallback.isAvailable()) { addCallback(new ServletCallback()); } }
Source:
SessionPayload(Collection<SessionCount> sessionCounts, Configuration configuration) { START this.sessionCounts.addAll(sessionCounts); END diagnostics = new Diagnostics(configuration); } would it be better here to just initialize the `ArrayList` with `sessionCounts` instead of calling `addAll`? Presumably initializing it would result in potentially less array resizing

Target:
SessionPayload(Collection<SessionCount> sessionCounts, Configuration configuration) { this.sessionCounts = sessionCounts; diagnostics = new Diagnostics(configuration); }
Source:
START public List<Exception> getExceptions() { END List<Exception> exceptions = new ArrayList<Exception>(); Throwable currentThrowable = throwable; while (currentThrowable != null) { exceptions.add(new Exception(config, currentThrowable)); currentThrowable = currentThrowable.getCause(); } return exceptions; } This either needs to be `protected` or `Exception` needs to be public.

Target:
protected List<Exception> getExceptions() { List<Exception> exceptions = new ArrayList<Exception>(); Throwable currentThrowable = throwable; while (currentThrowable != null) { exceptions.add(new Exception(config, currentThrowable)); currentThrowable = currentThrowable.getCause(); } return exceptions; }
Source:
START public List<ThreadState> getThreads() { END return config.sendThreads ? ThreadState.getLiveThreads(config) : null; } This either needs to be `protected` or `ThreadState` needs to be public.

Target:
protected List<ThreadState> getThreads() { return config.sendThreads ? ThreadState.getLiveThreads(config) : null; }
Source:
START public Report(Configuration config, Throwable throwable) { END this.config = config; this.throwable = throwable; } If the expectation is that this always get built from Bugsnag.buildReport we should remove the `public` here to make this package protected. This will enforce the API usage which will make it easier to maintain and refactor in the future.

Target:
protected Report(Configuration config, Throwable throwable) { this.config = config; this.throwable = throwable; }
Source:
public Table getTable(final String dbName, final String tableName, boolean throwException) throws HiveException { START return this.getTable(dbName, tableName, throwException, true); END } Why is this change? Should not this minimally depend on if this table is transactional or not? What happens if we call it on a non-transactional table?

Target:
public Table getTable(final String dbName, final String tableName, boolean throwException) throws HiveException { return this.getTable(dbName, tableName, throwException, false); }
Source:
public synchronized void addMetric(ReplicationMetric replicationMetric) throws SemanticException { if (metricMap.size() > maxSize) { throw new SemanticException("Metrics are not getting collected. "); } else { if (metricMap.size() > 0.8 * maxSize) { //soft limit LOG.warn("Metrics cache is more than 80 % full. Will start dropping metrics once full. "); } START metricMap.put(replicationMetric.getScheduledExecutionId(), replicationMetric); END } } We fail on addMetric() time only when size (of Concurrent Policies) hit the max. If we have say only 10 policies we are trying to failover we will not hit the max criteria. If sink is broken, addMetric() will never fail and we will not get the required metric for controlled failover ever?

Target:
public synchronized void addMetric(ReplicationMetric replicationMetric) throws SemanticException { if (metricMap.size() >= maxSize) { throw new SemanticException("Metrics are not getting collected. "); } else { if (metricMap.size() > 0.8 * maxSize) { //soft limit LOG.warn("Metrics cache is more than 80 % full. Will start dropping metrics once full. "); } metricMap.put(replicationMetric.getScheduledExecutionId(), replicationMetric); } }
Source:
START public List<AtlasObjectId> getItemsToExport(AtlasReplInfo atlasReplInfo, String srcAtlasServerName) { END List<AtlasObjectId> atlasObjectIds = new ArrayList<>(); final String qualifiedName = getQualifiedName(srcAtlasServerName, atlasReplInfo.getSrcDB()); atlasObjectIds.add(new AtlasObjectId(ATLAS_TYPE_HIVE_DB, ATTRIBUTE_QUALIFIED_NAME, qualifiedName)); return atlasObjectIds; } Do you need all methods to be public

Target:
private List<AtlasObjectId> getItemsToExport(AtlasReplInfo atlasReplInfo, String srcAtlasServerName) { List<AtlasObjectId> atlasObjectIds = new ArrayList<>(); final String qualifiedName = getQualifiedName(srcAtlasServerName, atlasReplInfo.getSrcDB()); atlasObjectIds.add(new AtlasObjectId(ATLAS_TYPE_HIVE_DB, ATTRIBUTE_QUALIFIED_NAME, qualifiedName)); return atlasObjectIds; }
Source:
START public void testWithNonZeroFraction() throws SemanticException { END if (intType) { testNullCase("100.1"); } } nit: in case throwing an exception from a testcase: it's better to throw plain Exception - then we never have to go back there

Target:
public void testWithNonZeroFraction() throws Exception { if (intType) { testNullCase("100.1"); } }
Source:
START DataSketchesFunctions() { END this.sketchClasses = new ArrayList<SketchDescriptor>(); this.descriptors = new ArrayList<HiveUDFPlugin.UDFDescriptor>(); registerHll(); registerCpc(); registerKll(); registerTheta(); registerTuple(); registerQuantiles(); registerFrequencies(); buildCalciteFns(); buildDescritors(); } `private`?

Target:
private DataSketchesFunctions() { this.sketchClasses = new ArrayList<SketchDescriptor>(); this.descriptors = new ArrayList<HiveUDFPlugin.UDFDescriptor>(); registerHll(); registerCpc(); registerKll(); registerTheta(); registerTuple(); registerQuantiles(); registerFrequencies(); buildCalciteFns(); buildDescritors(); }
Source:
private boolean shouldDump(Path previousDumpPath) throws IOException { //If no previous dump means bootstrap. So return true as there was no //previous dump to load if (previousDumpPath == null) { return true; } else { FileSystem fs = previousDumpPath.getFileSystem(conf); START if (fs.exists(previousDumpPath)) { END FileStatus[] latestUpdateStatuses = fs.listStatus(previousDumpPath); for (FileStatus status : latestUpdateStatuses) { if (status.getPath().getName().equalsIgnoreCase(ReplUtils.LOAD_ACKNOWLEDGEMENT)) { return true; } } } } return false; } Should we just use return fs.exists(new Path(previousDumpPath, ReplUtils.LOAD_ACKNOWLEDGEMENT));

Target:
private boolean shouldDump(Path previousDumpPath) throws IOException { //If no previous dump means bootstrap. So return true as there was no //previous dump to load if (previousDumpPath == null) { return true; } else { FileSystem fs = previousDumpPath.getFileSystem(conf); return fs.exists(new Path(previousDumpPath, ReplUtils.LOAD_ACKNOWLEDGEMENT)); } }
Source:
public SCOPE getScope(){ if (isInReplicationScope()){ START if (isMetadataOnly() || isMetadataOnlyForExternalTables()){ END return SCOPE.MD_ONLY; } else { return SCOPE.REPL; } } else { return SCOPE.NO_REPL; } } No need to change this

Target:
public SCOPE getScope(){ if (isInReplicationScope()){ if (isMetadataOnly()){ return SCOPE.MD_ONLY; } else { return SCOPE.REPL; } } else { return SCOPE.NO_REPL; } }
Source:
START public final void unSetClockBit() { END long val = state.get(); while (State.isClockBitSet(val) && !state.compareAndSet(val, State.unSetClockBit(val))) { val = state.get(); } } There isn't really a need for any unSet as each check against the clockBit (observed) should reset the clock bit.

Target:
public final boolean unSetClockBit() { long val = state.get(); if (!State.isClockBitSet(val)) return false; while (State.isClockBitSet(val)) { if (state.compareAndSet(val, State.unSetClockBit(val))) return true; val = state.get(); } return false; }
Source:
public void notifyLock(LlapCacheableBuffer buffer) { // We do not proactively remove locked items from the heap, and opportunistically try to // remove from the list (since eviction is mostly from the list). If eviction stumbles upon // a locked item in either, it will remove it from cache; when we unlock, we are going to // put it back or update it, depending on whether this has happened. This should cause // most of the expensive cache update work to happen in unlock, not blocking processing. START if (buffer.cacheAttribute == null || buffer.cacheAttribute.getIndex() != IN_LIST || !listLock.tryLock()) { END return; } removeFromListAndUnlock(buffer); } Question: what scenario can lead to a null cacheAttribute?

Target:
public void notifyLock(LlapCacheableBuffer buffer) { // We do not proactively remove locked items from the heap, and opportunistically try to // remove from the list (since eviction is mostly from the list). If eviction stumbles upon // a locked item in either, it will remove it from cache; when we unlock, we are going to // put it back or update it, depending on whether this has happened. This should cause // most of the expensive cache update work to happen in unlock, not blocking processing. if (buffer.cacheAttribute.getIndex() != IN_LIST || !listLock.tryLock()) { return; } removeFromListAndUnlock(buffer); }
Source:
public String generateInitFileName(String toVersion) throws HiveMetaException { if (toVersion == null) { toVersion = getHiveSchemaVersion(); } String initScriptName = INIT_FILE_PREFIX + toVersion + "." + dbType + SQL_FILE_EXTENSION; // check if the file exists File file = new File(getMetaStoreScriptDir() + File.separatorChar + initScriptName); START if (!(file.exists())) { END throw new HiveMetaException("Unknown version specified for initialization: " + toVersion, new NoSuchFileException(file.getAbsolutePath())); } return initScriptName; } nit. enclosing () for file not needed

Target:
public String generateInitFileName(String toVersion) throws HiveMetaException { if (toVersion == null) { toVersion = getHiveSchemaVersion(); } String initScriptName = INIT_FILE_PREFIX + toVersion + "." + dbType + SQL_FILE_EXTENSION; // check if the file exists File file = new File(getMetaStoreScriptDir() + File.separatorChar + initScriptName); if (!file.exists()) { throw new HiveMetaException("Unknown version specified for initialization: " + toVersion, new NoSuchFileException(file.getAbsolutePath())); } return initScriptName; }
Source:
public static void unregisterLoggingContext() { // Remove the keys added, don't use clear, as it may clear all other things which are not intended to be removed. MDC.remove(SESSIONID_LOG_KEY); MDC.remove(QUERYID_LOG_KEY); MDC.remove(OPERATIONLOG_LEVEL_KEY); l4j.info("Unregistered logging context."); START if (MDC.get(OPERATIONLOG_LEVEL_KEY) != null) { END throw new RuntimeException("Keys removal failed from thread context MDC"); } } why do we need this check here ?

Target:
public static void unregisterLoggingContext() { // Remove the keys added, don't use clear, as it may clear all other things which are not intended to be removed. MDC.remove(SESSIONID_LOG_KEY); MDC.remove(QUERYID_LOG_KEY); MDC.remove(OPERATIONLOG_LEVEL_KEY); l4j.info("Unregistered logging context."); }
Source:
MetaStoreConfigAuthenticationProviderImpl(Configuration conf) throws AuthenticationException { userName = MetastoreConf.getVar(conf, MetastoreConf.ConfVars.THRIFT_AUTH_CONFIG_USERNAME); password = MetastoreConf.getVar(conf, MetastoreConf.ConfVars.THRIFT_AUTH_CONFIG_PASSWORD); if (null == userName || userName.isEmpty()) { throw new AuthenticationException("No username specified in " + MetastoreConf.ConfVars.THRIFT_AUTH_CONFIG_USERNAME); } START if (null == password || password.isEmpty()) { END throw new AuthenticationException("No password specified in " + MetastoreConf.ConfVars.THRIFT_AUTH_CONFIG_USERNAME); } } password can be empty

Target:
MetaStoreConfigAuthenticationProviderImpl(Configuration conf) throws AuthenticationException { userName = MetastoreConf.getVar(conf, MetastoreConf.ConfVars.THRIFT_AUTH_CONFIG_USERNAME); password = MetastoreConf.getVar(conf, MetastoreConf.ConfVars.THRIFT_AUTH_CONFIG_PASSWORD); if (null == userName || userName.isEmpty()) { throw new AuthenticationException("No username specified in " + MetastoreConf.ConfVars.THRIFT_AUTH_CONFIG_USERNAME); } if (null == password) { throw new AuthenticationException("No password specified in " + MetastoreConf.ConfVars.THRIFT_AUTH_CONFIG_PASSWORD); } }
Source:
public Table get_table(final String dbname, final String name) throws MetaException, NoSuchObjectException { String[] parsedDbName = parseDbName(dbname, conf); return getTableInternal( START parsedDbName[CAT_NAME], parsedDbName[DB_NAME], name, null, null, false, null); END } Should this be null? Does that internally default to "hive" in getTableColumnStatistics()? Or is this safe because we are not getting column stats in this case?

Target:
public Table get_table(final String dbname, final String name) throws MetaException, NoSuchObjectException { String[] parsedDbName = parseDbName(dbname, conf); return getTableInternal( parsedDbName[CAT_NAME], parsedDbName[DB_NAME], name, null, null, false, null, null, null); }
Source:
public LlapManagementProtocolClientImpl create(LlapServiceInstance serviceInstance) { START LlapManagementProtocolClientImpl client = new LlapManagementProtocolClientImpl(conf, serviceInstance.getHost(), END serviceInstance.getManagementPort(), retryPolicy, socketFactory); return client; } Why storing it in client instead of returning it directly (which would be consistent with basicInstance)?

Target:
public LlapManagementProtocolClientImpl create(LlapServiceInstance serviceInstance) { return new LlapManagementProtocolClientImpl(conf, serviceInstance.getHost(), serviceInstance.getManagementPort(), retryPolicy, socketFactory); }
Source:
TimedAverageMetrics(int windowDataSize, long windowTimeSize) { START this(windowDataSize, windowTimeSize, System.nanoTime()); END } Using the current time as default time essentially makes all values valid within the time window. We therefore aggregate just zeros here. Wouldn't it make sense to initialize this with zero to mark all entries "outside of the window" initially?

Target:
TimedAverageMetrics(int windowDataSize, long windowTimeSize) { this(windowDataSize, windowTimeSize, System.nanoTime() - windowTimeSize - 1); }
Source:
public String getQueryId() throws SQLException { if (stmtHandle == null) { START return null; END } try { return client.GetQueryId(new TGetQueryIdReq(stmtHandle)).getQueryId(); } catch (TException e) { throw new SQLException(e); } } what about concurrent closure of statement ?

Target:
public String getQueryId() throws SQLException { if (stmtHandle == null) { // If query is not running or already closed. return null; } try { return client.GetQueryId(new TGetQueryIdReq(stmtHandle)).getQueryId(); } catch (TException e) { throw new SQLException(e); } catch (Exception e) { // If concurrently the query is closed before we fetch queryID. return null; } }
Source:
START ConstraintFileType(String name, String prefix) { END this.name = name; this.prefix = prefix; } Why do we need this change? I don't see this constructor being used outside this class.

Target:
private ConstraintFileType(String name, String prefix) { this.name = name; this.prefix = prefix; }
Source:
public TableType tableType() { if (isView()) { START return TableType.VIRTUAL_VIEW; END } else if (isMaterializedView()) { return TableType.MATERIALIZED_VIEW; } return table.getTableType(); } No need to check view type above. table.getTableType() suffice.

Target:
public TableType tableType() { return table.getTableType(); }
Source:
START public IMetaStoreClient getMSC() { END connectionStats.incrementMetastoreCalls(); return msClient; } is this required to be public? exposing the metastore client via streaming connection API seems to be risky as clients can mess with it.

Target:
IMetaStoreClient getMSC() { connectionStats.incrementMetastoreCalls(); return msClient; }
Source:
private void verifyIfCkptSet(Map<String, String> props, String dumpDir) { assertTrue(props.containsKey(ReplUtils.REPL_CHECKPOINT_KEY)); START assertTrue(props.get(ReplUtils.REPL_CHECKPOINT_KEY).equalsIgnoreCase(dumpDir)); END } for some file systems the path is case sensitive.

Target:
private void verifyIfCkptSet(Map<String, String> props, String dumpDir) { assertTrue(props.containsKey(ReplUtils.REPL_CHECKPOINT_KEY)); assertTrue(props.get(ReplUtils.REPL_CHECKPOINT_KEY).equals(dumpDir)); }
Source:
public void shouldNotCreateDirectoryForNonNativeTableInDumpDirectory() throws Throwable { String createTableQuery = "CREATE TABLE custom_serdes( serde_id bigint COMMENT 'from deserializer', name string " + "COMMENT 'from deserializer', slib string COMMENT 'from deserializer') " + "ROW FORMAT SERDE 'org.apache.hive.storage.jdbc.JdbcSerDe' " + "STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler' " + "WITH SERDEPROPERTIES ('serialization.format'='1') " + "TBLPROPERTIES ( " + "'hive.sql.database.type'='METASTORE', " + "'hive.sql.query'='SELECT \"SERDE_ID\", \"NAME\", \"SLIB\" FROM \"SERDES\"')"; WarehouseInstance.Tuple bootstrapTuple = primary .run("use " + primaryDbName) .run(createTableQuery).dump(primaryDbName, null); START Path cSerdesTableDumpLocation = new Path(bootstrapTuple.dumpLocation END + Path.SEPARATOR + primaryDbName + Path.SEPARATOR + "custom_serdes"); FileSystem fs = cSerdesTableDumpLocation.getFileSystem(primary.hiveConf); assertFalse(fs.exists(cSerdesTableDumpLocation)); } instead of path separator create new path to make it generic

Target:
public void shouldNotCreateDirectoryForNonNativeTableInDumpDirectory() throws Throwable { String createTableQuery = "CREATE TABLE custom_serdes( serde_id bigint COMMENT 'from deserializer', name string " + "COMMENT 'from deserializer', slib string COMMENT 'from deserializer') " + "ROW FORMAT SERDE 'org.apache.hive.storage.jdbc.JdbcSerDe' " + "STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler' " + "WITH SERDEPROPERTIES ('serialization.format'='1') " + "TBLPROPERTIES ( " + "'hive.sql.database.type'='METASTORE', " + "'hive.sql.query'='SELECT \"SERDE_ID\", \"NAME\", \"SLIB\" FROM \"SERDES\"')"; WarehouseInstance.Tuple bootstrapTuple = primary .run("use " + primaryDbName) .run(createTableQuery).dump(primaryDbName, null); Path cSerdesTableDumpLocation = new Path( new Path(bootstrapTuple.dumpLocation, primaryDbName), "custom_serdes"); FileSystem fs = cSerdesTableDumpLocation.getFileSystem(primary.hiveConf); assertFalse(fs.exists(cSerdesTableDumpLocation)); }
Source:
START protected static void closeStmt(Statement stmt) { END try { if (stmt != null && !stmt.isClosed()) { stmt.close(); } } catch (SQLException e) { LOG.warn("Failed to close statement " + e.getMessage()); } } Access can be private for both close methods. Also, can we merge them into one method?

Target:
private static void closeStmt(Statement stmt) { try { if (stmt != null && !stmt.isClosed()) { stmt.close(); } } catch (SQLException e) { LOG.warn("Failed to close statement " + e.getMessage()); } }
Source:
private void verifyResultsInReplica(List<String> selectStmtList, List<String[]> expectedValues) throws Throwable { START for (int idx = 0; idx > selectStmtList.size(); idx++) { END replica.run("use " + replicatedDbName) .run(selectStmtList.get(idx)) .verifyResults(expectedValues.get(idx)); } } This loop will never execute as condition is >.

Target:
private void verifyResultsInReplica(List<String> selectStmtList, List<String[]> expectedValues) throws Throwable { for (int idx = 0; idx < selectStmtList.size(); idx++) { replica.run("use " + replicatedDbName) .run(selectStmtList.get(idx)) .verifyResults(expectedValues.get(idx)); } }
Source:
public void alterCatalog(String catName, Catalog cat) throws MetaException, InvalidOperationException { rawStore.alterCatalog(catName, cat); START catName = catName.toLowerCase(); END sharedCache.alterCatalogInCache(StringUtils.normalizeIdentifier(catName), cat); } StringUtils.normalizeIdentifier does lowercase as well, so this is not necessary. Same issue is present in getDatabase (but not introduced by your patch).

Target:
public void alterCatalog(String catName, Catalog cat) throws MetaException, InvalidOperationException { rawStore.alterCatalog(catName, cat); sharedCache.alterCatalogInCache(StringUtils.normalizeIdentifier(catName), cat); }
Source:
public String getReplPolicy() { START if (dbName == null) { END return null; } else if (tableName == null) { return dbName.toLowerCase() + ".*"; } else { return dbName.toLowerCase() + "." + tableName.toLowerCase(); } } Better to check for blank string as well. StringUtils.isEmpty() can be used.

Target:
public String getReplPolicy() { if ((dbName == null) || (dbName.isEmpty())) { return null; } else if ((tableName == null) || (tableName.isEmpty())) { return dbName.toLowerCase() + ".*"; } else { return dbName.toLowerCase() + "." + tableName.toLowerCase(); } }
Source:
public ReplTxnWork(String dbName, String tableName, Long txnId, OperationType type) { START this.txnIds = Lists.newArrayList(); END this.txnIds.add(txnId); this.dbName = dbName; this.tableName = tableName; this.operation = type; } Shall initialise using newArrayList(txnId) instead of 2 statements.

Target:
public ReplTxnWork(String dbName, String tableName, Long txnId, OperationType type) { this.txnIds = Lists.newArrayList(txnId); this.dbName = dbName; this.tableName = tableName; this.operation = type; }
Source:
public static ValidWriteIdList getTableValidWriteIdList(Configuration conf, String fullTableName) { String txnString = conf.get(ValidTxnWriteIdList.VALID_TABLES_WRITEIDS_KEY); START ValidTxnWriteIdList validTxnList = new ValidTxnWriteIdList(txnString); END return validTxnList.getTableWriteIdList(fullTableName); } should this do something meaningful if key is not found? Seems like that would be an error condition. This seems like it may mask issues.

Target:
public static ValidWriteIdList getTableValidWriteIdList(Configuration conf, String fullTableName) { String txnString = conf.get(ValidTxnWriteIdList.VALID_TABLES_WRITEIDS_KEY); ValidTxnWriteIdList validTxnList = new ValidTxnWriteIdList(txnString); return validTxnList.getTableValidWriteIdList(fullTableName); }
Source:
public ConstraintEventsIterator(String dumpDirectory, HiveConf hiveConf) throws IOException { Path path = new Path(dumpDirectory); fs = path.getFileSystem(hiveConf); dbDirs = fs.listStatus(new Path(dumpDirectory), EximUtil.getDirectoryFilter(fs)); currentDbIndex = 0; if (dbDirs.length != 0) { START currentConstraintIndex = 0; END constraintFiles = listConstraintFilesInDBDir(fs, dbDirs[0].getPath()); } } Constraint files listing for 0th Db also can be done inside hasNext to avoid duplicate code here.

Target:
public ConstraintEventsIterator(String dumpDirectory, HiveConf hiveConf) throws IOException { path = new Path(dumpDirectory); fs = path.getFileSystem(hiveConf); }
Source:
START static Path getCMPath(Configuration conf, String checkSum) throws IOException, MetaException { END String newFileName = checkSum; int maxLength = conf.getInt(DFSConfigKeys.DFS_NAMENODE_MAX_COMPONENT_LENGTH_KEY, DFSConfigKeys.DFS_NAMENODE_MAX_COMPONENT_LENGTH_DEFAULT); if (newFileName.length() > maxLength) { newFileName = newFileName.substring(0, maxLength-1); } return new Path(cmroot, newFileName); } Just noticed that those exceptions are not thrown by this method and as we making changes in this code, thought may be make these changes as well. If you don't want to make those changes part of this path, that's fine as well.

Target:
static Path getCMPath(Configuration conf, String checkSum) { String newFileName = checkSum; int maxLength = conf.getInt(DFSConfigKeys.DFS_NAMENODE_MAX_COMPONENT_LENGTH_KEY, DFSConfigKeys.DFS_NAMENODE_MAX_COMPONENT_LENGTH_DEFAULT); if (newFileName.length() > maxLength) { newFileName = newFileName.substring(0, maxLength-1); } return new Path(cmroot, newFileName); }
Source:
private static String getMetastoreJdbcPasswd(HiveConf conf) { try { return ShimLoader.getHadoopShims().getPassword(conf, HiveConf.ConfVars.METASTOREPWD.varname); } catch (IOException io) { START } END return null; } shouldn't this be throwing the exception ?

Target:
private static String getMetastoreJdbcPasswd(HiveConf conf) throws IOException { return ShimLoader.getHadoopShims().getPassword(conf, HiveConf.ConfVars.METASTOREPWD.varname); }
Source:
private void setupHistory() throws IOException { if (this.history != null) { return; } this.history = new FileHistory(new File(getOpts().getHistoryFile())); // add shutdown hook to flush the history to history file and to close all open connections ShutdownHookManager.addShutdownHook(new Runnable() { @Override public void run() { try { history.flush(); } catch (IOException e) { error(e); START } finally { END close(); } } }); } This shutdown hook is being added as part of setupHistory method, using that for close is not very clean. Maybe create a separate function for adding shutdown hook ?

Target:
private void setupHistory() throws IOException { if (this.history != null) { return; } this.history = new FileHistory(new File(getOpts().getHistoryFile())); }
Source:
public TJobExecutionStatus forStatus(String status) { try { TezStatus tezStatus = TezStatus.valueOf(status); switch (tezStatus) { case SUBMITTED: case INITING: case RUNNING: return TJobExecutionStatus.IN_PROGRESS; default: return TJobExecutionStatus.COMPLETE; } } catch (IllegalArgumentException ex) { START LOG.debug("Could not understand the status from tez execution engine : " + status); END return TJobExecutionStatus.NOT_AVAILABLE; } } I think LOG.warn might be more suited for this message. We don't expect this to happen.

Target:
public TJobExecutionStatus forStatus(String status) { if (StringUtils.isEmpty(status)) { return TJobExecutionStatus.NOT_AVAILABLE; } TezStatus tezStatus = TezStatus.valueOf(status); switch (tezStatus) { case SUBMITTED: case INITING: case RUNNING: return TJobExecutionStatus.IN_PROGRESS; default: return TJobExecutionStatus.COMPLETE; } }
Source:
START private static GroupType buildProjectedGroupType( END GroupType originalType, List<Type> types) { return new GroupType(originalType.getRepetition(), originalType.getName(), types); } (minor suggestion) I think this func along with `projectLeafTypes` can be combined into one to make it more clear: `private static GroupType buildProjectedGroupType(GroupType originalType, List<String> groupPaths, String currentPath) { .... } ` Perhaps return null if none of the group fields get included.

Target:
private static GroupType buildProjectedGroupType( GroupType originalType, List<Type> types) { if (types == null || types.isEmpty()) { return null; } return new GroupType(originalType.getRepetition(), originalType.getName(), types); }
Source:
public void write(JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeStringField("type", type); START switch ("type") { END case "NOT": writeField(generator, "field", fields.get(0)); break; default: writeField(generator, "fields", fields); } generator.writeEndObject(); } Should be `switch (type)`?

Target:
public void write(JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeStringField("type", type); switch (type) { case "NOT": writeField(generator, "field", fields.get(0)); break; default: writeField(generator, "fields", fields); } generator.writeEndObject(); }
Source:
public static AcidStats parseAcidStats(Reader reader) { if (reader.hasMetadataValue(ACID_STATS)) { String statsSerialized; try { START ByteBuffer val = END reader.getMetadataValue(ACID_STATS) .duplicate(); statsSerialized = utf8Decoder.decode(val).toString(); } catch (CharacterCodingException e) { throw new IllegalArgumentException("Bad string encoding for " + ACID_STATS, e); } return new AcidStats(statsSerialized); } else { return null; } } nit: bad alignment

Target:
public static AcidStats parseAcidStats(Reader reader) { if (reader.hasMetadataValue(ACID_STATS)) { try { ByteBuffer val = reader.getMetadataValue(ACID_STATS).duplicate(); return new AcidStats(utf8Decoder.decode(val).toString()); } catch (CharacterCodingException e) { throw new IllegalArgumentException("Bad string encoding for " + ACID_STATS, e); } } else { return null; } }
Source:
public HivePrincipal getHivePrincipal(PrincipalDesc principal) throws HiveException { START return AuthorizationUtils.getHivePrincipal(principal); END } It looks weird. Do we still need `getHivePrincipal` for the `AuthorizationUtils`? We can move the implementation of these three APIs to the translator. And remove that in `AuthorizationUtils`.

Target:
public HivePrincipal getHivePrincipal(PrincipalDesc principal) throws HiveException { if (principal == null) { return null; } return AuthorizationUtils.getHivePrincipal(principal.getName(), principal.getType()); }
Source:
public InstanceOfExpr(final Expression expression, final ReferenceType type) { START this(null, expression, type); END } In all the other nodes, all the constructors call the most specific constructor to avoid constructor spaghetti. That would mean the this-call gets "null" at the end for example.

Target:
public InstanceOfExpr(final Expression expression, final ReferenceType type) { this(null, expression, type, null); }
Source:
public void commentBeforeBlock() { Statement st = StaticJavaParser.parseBlock( "// a comment before parent" + System.lineSeparator() + "{ if (file != null) }"); assertTrue(st.getComment().isPresent()); assertTrue(st.getOrphanComments().isEmpty()); START assertEquals(1, st.getAllContainedComments()); END } Im confused how this works... st.getAllContainedComments() returns a list RIGHT? so how can a list be equal to 1? shouldnt it be : `st.getAllContainedComments.size()`

Target:
public void commentBeforeBlock() { Statement st = StaticJavaParser.parseBlock( "// a comment before parent" + System.lineSeparator() + "{ if (file != null) }"); assertTrue(st.getComment().isPresent()); assertTrue(st.getOrphanComments().isEmpty()); assertEquals(0, st.getAllContainedComments().size()); }
Source:
void getters() { assertEquals("getValue", getterName(Object.class, "value")); assertEquals("isBlue", getterName(Boolean.TYPE, "isBlue")); START assertEquals("isBlue", getterName(Boolean.TYPE, "blue")); END assertEquals("getBlue", getterName(Boolean.class, "blue")); assertEquals("getIsBlue", getterName(Boolean.class, "isBlue")); } Yeah, I thought the subtle capitalization change might cause misunderstanding ;-) I think it's more expressive because "TYPE" vs "class" is not as direct as `boolean` vs `Boolean`... although you could argue against it because of the subtle caps. Make it as you like.

Target:
void getters() { assertEquals("getValue", getterName(Object.class, "value")); assertEquals("isBlue", getterName(boolean.class, "isBlue")); assertEquals("isBlue", getterName(boolean.class, "blue")); assertEquals("getBlue", getterName(Boolean.class, "blue")); assertEquals("getIsBlue", getterName(Boolean.class, "isBlue")); }
Source:
default boolean hasParametersOfType(String... paramTypes) { return getParameters().stream() .map(p -> p.getType().asString()) .collect(toList()) START .equals(Stream.of(paramTypes).collect(toList())); END } Arrays,asList prevents a stream/collect

Target:
default boolean hasParametersOfType(String... paramTypes) { return getParameters().stream() .map(p -> p.getType().asString()) .collect(toList()) .equals(Arrays.asList(paramTypes)); }
Source:
void noModifiersInForEachBesideFinal() { ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("for(static transient int i : nums){}")); assertProblems(result, "(line 1,col 5) 'static' is not allowed here.", "(line 1,col 5) 'transient' is not allowed here.", START "(line 1,col 1) A foreach statement's variable declaration may have at most one 'final' modifier, and no other modifiers. Given: [static , transient ]."); END } Hmmm, three messages are a little overkill?

Target:
void noModifiersInForEachBesideFinal() { ParseResult<Statement> result = javaParser.parse(STATEMENT, provider("for(static transient int i : nums){}")); assertProblems(result, "(line 1,col 5) 'static' is not allowed here.", "(line 1,col 5) 'transient' is not allowed here."); }
Source:
public void parseModuleDeclaration() { START JavaParser.getStaticConfiguration().setLanguageLevel(JAVA_9); END JavaParser.parseModuleDeclaration("module X {}"); } Is it good to change the static configuration in a test?

Target:
public void parseModuleDeclaration() { JavaParser.parseModuleDeclaration("module X {}"); }
Source:
public Iterable<Node> treeIterable(TreeTraversal traversal) { START return () -> treeIterator(traversal); END } Wow!

Target:
private Iterable<Node> treeIterable(TreeTraversal traversal) { return () -> treeIterator(traversal); }
Source:
private static <T extends Node> T simplifiedParse(ParseStart<T> context, Provider provider) { ParseResult<T> result = new JavaParser(staticConfiguration).parse(context, provider); if (result.isSuccessful()) { START considerInjectingSymbolResolver(result, staticConfiguration); END return result.getResult().get(); } throw new ParseProblemException(result.getProblems()); } This is already done in the other method.

Target:
private static <T extends Node> T simplifiedParse(ParseStart<T> context, Provider provider) { ParseResult<T> result = new JavaParser(staticConfiguration).parse(context, provider); if (result.isSuccessful()) { return result.getResult().get(); } throw new ParseProblemException(result.getProblems()); }
Source:
public void arrayType() { Type type = parseType("int[]"); assertTrue(type.isArrayType()); ArrayType arrayType = type.asArrayType(); final ArrayType[] s = new ArrayType[1]; START type.ifArrayType(t -> s[0] = (ArrayType)t); END assertNotNull(s[0]); } Huh? The point is that a cast isn't necessary

Target:
public void arrayType() { Type type = parseType("int[]"); assertTrue(type.isArrayType()); ArrayType arrayType = type.asArrayType(); final ArrayType[] s = new ArrayType[1]; type.ifArrayType(t -> s[0] = t); assertNotNull(s[0]); }
Source:
public void ifBlockComment(Consumer<BlockComment> action) { START if (isBlockComment()) { END action.accept(asBlockComment()); } } this one could be empty I guess

Target:
public void ifBlockComment(Consumer<BlockComment> action) { }
Source:
public static boolean isComment(int kind) { START return getCategory(kind)== JavaToken.Category.COMMENT; END } for the other categories you are using just the name (COMMENT instead of JavaToken.Category.COMMENT), also a space before `==`

Target:
public static boolean isComment(int kind) { return getCategory(kind).isComment(); }
Source:
public String toText() { START StringBuffer sb = new StringBuffer(); END elements.forEach(e -> sb.append(e.toText())); return sb.toString(); } Replace with StringBuilder here too

Target:
public String toText() { StringBuilder sb = new StringBuilder(); elements.forEach(e -> sb.append(e.toText())); return sb.toString(); }
Source:
START public default <A extends Statement> A addAndGetStatement(A statement) { END getStmts().add(statement); statement.setParentNode((Node) this); return statement; } Intellij tells me that "public" is not necessary here.

Target:
default <A extends Statement> A addAndGetStatement(A statement) { getStmts().add(statement); statement.setParentNode((Node) this); return statement; }