auphong2707/dl4se-code-review-dataset huggingface dataset:
Source:
private long determineSizesSerial(long recordsToReadInThisPass) throws IOException { int recordsReadInCurrentPass = 0; top: do { for (VarLengthColumn<?> columnReader : columns) { // Return status is "done reading", meaning stop if true. if (columnReader.determineSize(recordsReadInCurrentPass, 0 /* unused */ )) { break top; } } for (VarLengthColumn<?> columnReader : columns) { columnReader.updateReadyToReadPosition(); columnReader.currDefLevel = -1; } recordsReadInCurrentPass++; } while (recordsReadInCurrentPass < recordsToReadInThisPass); return recordsReadInCurrentPass; }

Target:
why not remove the unused parameter ?
Source:
public FragmentContext getContext() { return incoming.getContext(); }

Target:
OK, so we hold onto the incoming batch just to get the FragmentContext. If so, please pass the FragmentContext into the constructor of this class rather than passing in the (irrelevant) incoming batch.
Source:
public ContextInformation(final UserCredentials userCredentials, final QueryContextInformation queryContextInfo) { this.queryUser = userCredentials.getUserName(); this.currentDefaultSchema = queryContextInfo.getDefaultSchemaName(); this.queryStartTime = queryContextInfo.getQueryStartTime(); this.rootFragmentTimeZone = queryContextInfo.getTimeZone(); this.sessionId = queryContextInfo.getSessionId(); this.hllAccuracy = queryContextInfo.getHllAccuracy(); }

Target:
The query context is very general and is probably not the place to store specific options such as the hllAccuracy. The operator and/or factory can get the value directly from the option manager. Actually, any stats options should be set on the operator definition itself (`StatisticsAggregate`, etc.) so that all fragments use the same value: the one selected when creating the plan. This behavior would mimic how we set memory for sort operators, etc.
Source:
public MSorter createNewMSorter(VectorAccessible batch) { if (mSorter == null) { mSorter = createNewMSorter(popConfig.getOrderings(), batch, MAIN_MAPPING, LEFT_MAPPING, RIGHT_MAPPING); } return mSorter; }

Target:
Maybe change the method name to getMSorter() ? As internally it does not always create a new MSorter.
Source:
public ColumnDef( MockColumn mockCol, int rep ) { this( mockCol ); name = name += Integer.toString(rep); }

Target:
Below should also work. no need to reassign. `name += Integer.toString(rep);`
Source:
public static void tearDownCluster() throws Exception { synchronized (MongoTestSuit.class) { if (initCount.decrementAndGet() == 0) { if (mongoClient != null) { mongoClient.dropDatabase(EMPLOYEE_DB); mongoClient.close(); } if (distMode) { DistributedMode.cleanup(); } else { SingleMode.cleanup(); } } } }

Target:
Should the above include error handling? It seems that if the `dropDatabase` fails, then `close()` won't be called, nor will the `cleanup` method.
Source:
public Writer getWriter(PhysicalOperator child) throws IOException { if (!(formatPlugin.supportsAutoPartitioning() || partitionColumns == null || partitionColumns.size() == 0)) { throw UserException.unsupportedError().message(String.format("%s format does not support auto-partitioning.", formatPlugin.getName())).build(logger); } AbstractWriter writer = formatPlugin.getWriter(child, location, partitionColumns); if (storageStrategy != null) { writer.setStorageStrategy(storageStrategy); } return writer; }

Target:
Can the `setStorageStrategy` method accept a null storage strategy? Substitute `PERSISTENT` for null? Doing so will save the != null checks here and anywhere else that the method is called.
Source:
public void addClass( String fqcn, byte[] byteCodes ) { assert ! cache.containsKey( fqcn ); Class<?> newClass = defineClass(fqcn, byteCodes, 0, byteCodes.length); cache.put( fqcn, newClass ); }

Target:
Please use Guava Preconditions.checkState(cache.containsKey(fqcn), "your error message");
Source:
public void addClasses(Map<String, byte[]> results) { for ( String key : results.keySet() ) { addClass( key, results.get( key ) ); } }

Target:
Using iteration over map via entry set is more efficient than via key set: for (Map.Entry<String, byte[]> result : results.entrySet()) { addClass(result.getKey(), result.getValue()); }
Source:
public InvalidConnectionInfoException(String message) { this.message = message; }

Target:
Just use the normal facilities: ``` public Invalid...( String message ) { super( message ); } ... e.getMessage( ) ... ```
Source:
private String getHostName() throws UnknownHostException{ // DRILL_HOST_NAME sets custom host name. See drill-env.sh for details. String customHost = System.getenv("DRILL_HOST_NAME"); if (customHost == null) { return useIP ? InetAddress.getLocalHost().getHostAddress() : InetAddress.getLocalHost().getCanonicalHostName(); } else { return customHost; } }

Target:
Minor code flow suggestion: ``` if (customHost == null) { return customHost; } return useIP ? InetAddress.getLocalHost().getHostAddress() : InetAddress.getLocalHost().getCanonicalHostName(); ```
Source:
public RowGroupInfo(@JsonProperty("path") String path, @JsonProperty("start") long start, @JsonProperty("length") long length, @JsonProperty("rowGroupIndex") int rowGroupIndex, long rowCount) { super(path, start, length); this.rowGroupIndex = rowGroupIndex; this.rowCount = rowCount; this.numRecordsToRead = rowCount; this.preferredEndpoint = null; }

Target:
Not required.
Source:
public synchronized long skip(long n) throws IOException { checkInputStreamState(); long bytesAvailable = this.count - this.curPosInBuffer; long bytesSkipped = 0; if (n <= 0) { return 0; } if (bytesAvailable <= 0) { checkInputStreamState(); bytesAvailable = getNextBlock(); if (bytesAvailable <= 0) { // End of stream return 0; } } bytesSkipped = bytesAvailable < n ? bytesAvailable : n; this.curPosInBuffer += bytesSkipped; return bytesSkipped; }

Target:
Not sure the semantics of this are exactly correct... The InputStream version seeks forward by n bytes. This implementation seems to seek forward only within the data **in the buffer**. It does not (seem) to "Skips over and discards n bytes of data from this input stream." as InputStream does.
Source:
public static BooleanType get(String literal) { String value = literal.toLowerCase().trim(); BooleanType booleanType = allLiterals.get(value); if (booleanType == null) { throw new IllegalArgumentException("Invalid value for boolean: " + literal); } return booleanType; }

Target:
How is this exception handled?
Source:
private void connect(DrillbitEndpoint endpoint) throws RpcException { client.connect(endpoint, parameters, getUserCredentials()).checkedGet(); if (client.serverRequiresAuthentication()) { try { client.authenticate(null).checkedGet(); } catch (SaslException e) { throw new RpcException(e); } } }

Target:
what if the server doesn't require authentication, shouldn't the client wait too?
Source:
public V get(final String key) { return get(key, null); }

Target:
Minor point... Should this version simply call client.get as before? Should the version that takes a version require the version? Would seem to keep things a bit simpler that way...
Source:
public long getVersion() { try (AutoCloseableLock lock = readLock.open()) { return version.get(); } }

Target:
It seems that the version number is always protected by a read or write lock. Does it need to be an atomic long? If so, what does the atomic long get us that a (lock protected) long does not?
Source:
public long getInSubqueryThreshold() { return options.getOption(IN_SUBQUERY_THRESHOLD.getOptionName()).num_val; }

Target:
Change the declaration to: `public static final LongValidator IN_SUBQUERY_THRESHOLD ...` and here, `return options.getOption(IN_SUBQUERY_THRESHOLD;`
Source:
public List<SqlNode> getOperandList() { List<SqlNode> ops = Lists.newArrayList(); ops.add(tableName); ops.add(SqlLiteral.createBoolean(tableExistenceCheck, SqlParserPos.ZERO)); return ops; }

Target:
Use `ImmutableList`
Source:
public void start() { if (started) { return; } synchronized (queuedEvents) { started = true; isProcessing = true; } processEvents(); }

Target:
Please add docs here.
Source:
public FormatCreator getFormatCreator(final Configuration fsConf) { if (formatCreator == null) { formatCreator = new FormatCreator(dContext, fsConf, fsConfig, dContext.getClasspathScan()); } return formatCreator; }

Target:
Is the `FormatCreator` instance tied to some settings in `fsConf`? If yes, wouldn't a subsequent invocation of this function ignore the passed `fsConf` with different values of such settings?
Source:
protected String getBaseTableLocation() { final FormatSelection origSelection = (FormatSelection) table.getSelection(); return origSelection.getSelection().selectionRoot; }

Target:
I do not find this method being used outside this class. Is it intentional?
Source:
public void testSubmitPlanSingleNode() throws Exception { startCluster(1); DrillClient client = DrillClient.newBuilder().build(); client.connect(); List<QueryDataBatch> results = client.runQuery(QueryType.LOGICAL, plan); for (QueryDataBatch result : results) { System.out.println(result); result.release(); } client.close(); }

Target:
Let's keep the default constructor to be the same as the default builder. No reason to force a builder when there are no properties.
Source:
public boolean isTypeInferenceEnabled() { return options.getOption(TYPE_INFERENCE.getOptionName()).bool_val; }

Target:
``` java return option.getOption(TYPE_INFERENCE); ```
Source:
public void close() { if (hjHelper != null) { hjHelper.clear(); } // If we didn't receive any data, hyperContainer may be null, check before clearing if (hyperContainer != null) { hyperContainer.clear(); } if (hashTable != null) { hashTable.clear(); } container.clear(); outputAllocator.close(); super.close(); }

Target:
outputAllocator can be null, right ?
Source:
protected FileSelection(final FileSelection selection) { Preconditions.checkNotNull(selection, "selection cannot be null"); this.statuses = selection.statuses; this.files = selection.files; this.selectionRoot = selection.selectionRoot; this.dirStatus = new BitSet(StatusType.values().length); }

Target:
Should this constructor copy the dirStatus from the input "selection" as well?
Source:
public void close() throws Exception { profileStore.close(); transientProfiles.close(); }

Target:
AutoCloseables.close(...)
Source:
public <V> TransientStore<V> getOrCreateTransientStore(final TransientStoreConfig<V> config) { final ZkEphemeralStore<V> store = (ZkEphemeralStore<V>)factory.getOrCreateStore(config); try { store.start(); } catch (final Exception e) { throw new DrillRuntimeException("unable to start zookeeper transient store", e); } return store; }

Target:
Accessing profiles will trigger starting the store again, which will cause an "already started" exception.
Source:
private void updatePeak() { final long currentMemory = locallyHeldMemory.get(); while (true) { final long previousPeak = peakAllocation.get(); if (currentMemory > previousPeak) { if (peakAllocation.compareAndSet(previousPeak, currentMemory)) { // if we're able to update peak, finish. return; } else { // peak allocation changed underneath us. try again. continue; } } else { return; } } }

Target:
Is this loop equivalent to the following? ``` do { final long previousPeak = peakAllocation.get(); if (peakAllocation.compareAndSet(previousPeak, currentMemory)) { // if we're able to update peak, finish. return; } } while(currentMemory > previousPeak) ``` that feels more natural to me.
Source:
private void childClosed(final BaseAllocator childAllocator) { if (DEBUG) { Preconditions.checkArgument(childAllocator != null, "child allocator can't be null"); synchronized (DEBUG_LOCK) { final Object object = childAllocators.remove(childAllocator); if (object == null) { childAllocator.historicalLog.logHistory(logger); throw new IllegalStateException("Child allocator[" + childAllocator.id + "] not found in parent allocator[" + id + "]'s childAllocators"); } } } }

Target:
any reason we use `allocator.id` here and `name` in other places ? it makes it harder to follow the logs because we don't know which `id` corresponds to which `name`
Source:
public void eval() { org.apache.drill.exec.util.ByteBufUtil.checkBufferLength(in.buffer, in.start, in.end, 8); in.buffer.readerIndex(in.start); long epochMillis = Long.reverseBytes(in.buffer.readLong()); in.buffer.readerIndex(0); long millsOfDay = epochMillis % (24*3600*1000); out.value = epochMillis - millsOfDay; }

Target:
Can you explain why this is necessary? It seems like the issue you are trying to resolve is related to whatever comes after this function rather than an issue with this function. There should not be any guarantees about the reader index of a Drillbuf (in fact, we should remove this from being exposed in functions). See how this function positions the reader before doing anything else. Is there some other operation which doesn't position the reader? We should apply the fix there.
Source:
public SequenceFileRecordReader(final FileSplit split, final DrillFileSystem dfs, final String queryUserName, final String opUserName) { final List<SchemaPath> columns = new ArrayList(); columns.add(keySchema); columns.add(valueSchema); setColumns(columns); this.dfs = dfs; this.split = split; this.queryUserName = queryUserName; this.opUserName = opUserName; }

Target:
new ArrayList<>();
Source:
public static boolean isUnion(MajorType toType) { if (toType.getMinorType() == MinorType.UNION) { return true; } return false; }

Target:
probably better as return toType.getMinorType() == MinorType.UNION;
Source:
public void putChild(String name, ValueVector vector) { putVector(name, vector); field.addChild(vector.getField()); }

Target:
If we're making this more public, isn't there some way we can verify that what is being loaded is right? Also, why isn't protected enough?
Source:
protected void killIncoming(boolean sendUpstream) { close(); left.kill(sendUpstream); right.kill(sendUpstream); }

Target:
You shouldn't call close here. I believe that should come from the FragmentExecutor.
Source:
public int getBufferSizeFor(int valueCount) { if (getAccessor().getValueCount() == 0) { return 0; } return offsets.getBufferSizeFor(valueCount) + vector.getBufferSizeFor(valueCount); }

Target:
This first one should be passed valueCount +1 right? As was done in VariableLengthVectors.java
Source:
public void deleteOption(final String name, final OptionType type) { try { SystemOptionManager.getValidator(name); // ensure the option exists } catch (final IllegalArgumentException e) { throw UserException.validationError(e) .build(logger); } // fallback if unable to delete locally if (!deleteLocalOption(name, type)) { fallback.deleteOption(name, type); } }

Target:
you should call `name.toLowerCase()` here to make sure implementation will always be case insensitive.
Source:
public void shutdownIfClient() { if (bus.isClient()) { try { Closeables.close(bus, true); } catch (Exception e) { /* do nothing */ } } }

Target:
Any particular reason you added this ? is it safe to just ignore runtime exceptions here ?
Source:
public void sort(SelectionVector4 vector4, VectorContainer container){ Stopwatch watch = Stopwatch.createStarted(); watch.start(); QuickSort qs = new QuickSort(); qs.sort(this, 0, vector4.getTotalCount()); logger.debug("Took us to sort records", watch.elapsed(TimeUnit.MICROSECONDS), vector4.getTotalCount()); }

Target:
forgot to remove `watch.start()`
Source:
public synchronized static Set<Class<? extends StoragePluginConfig>> getSubTypes(final ScanResult classpathScan) { final Set<Class<? extends StoragePluginConfig>> packages = classpathScan.getImplementations(StoragePluginConfig.class); logger.debug("Found logical operator classes: {}.", packages.size(), packages); return packages; }

Target:
does this still need synchronized?
Source:
public DrillResultSetImpl newResultSet(AvaticaStatement statement, AvaticaPrepareResult prepareResult, TimeZone timeZone) { final ResultSetMetaData metaData = newResultSetMetaData(statement, prepareResult.getColumnList()); return new DrillResultSetImpl(statement, (DrillPrepareResult) prepareResult, metaData, timeZone); }

Target:
Cast here is redundant here, DrillResultSetImpl() is expecting an AvaticaPrepareResult object
Source:
public static SessionMap create(Config config) { Tracer tracer = new LoggingOptions(config).getTracer(); EventBus bus = new EventBusOptions(config).getEventBus(); JdbcSessionMapOptions sessionMapOptions = new JdbcSessionMapOptions(config); Connection connection; try { connection = sessionMapOptions.getJdbcConnection(); } catch (SQLException e) { throw new ConfigException(e.toString()); } return new JdbcBackedSessionMap(tracer, connection, bus); }

Target:
Maybe add the underlying exception too? `new ConfigException(e)`
Source:
public void tearDown() { if (authenticator != null) ((HasVirtualAuthenticator) driver).removeVirtualAuthenticator(authenticator); }

Target:
Nit: we tend to always use braces in the selenium codebase. It makes it harder to cause chaos accidentally :)
Source:
public static Collection<Supplier<Object[]>> buildGrids() { return ImmutableSet.of( () -> { try { return createRemotes(); } catch (URISyntaxException | SSLException | CertificateException e) { throw new RuntimeException(e); } }, () -> { try { return createInMemory(); } catch (Exception e) { throw new RuntimeException(e); } }); }

Target:
Nit please alphabetise.
Source:
public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Select select = (Select) o; return Objects.equals(element, select.element); }

Target:
Nowadays, we tend to follow a pattern of: ``` if (!(o instanceof Select)) { return false; } Select that = (Select) o; return Objects.equals(this.element, that.element); ```
Source:
public ChromeOptions merge(Capabilities extraCapabilities) { super.merge(extraCapabilities); if (extraCapabilities instanceof ChromeOptions) { Map options = (Map) extraCapabilities.asMap().get("goog:chromeOptions"); mergeArguments(options); mergeExtensions(options); mergeExtensionFiles(extraCapabilities); mergeBinary(options); mergeExperimentalOptions(extraCapabilities); } return this; }

Target:
Please use generics. If there's no obvious type, the `Map<?, ?>` prevents compiler warnings, is correct, and is equally meaningless :)
Source:
public FirefoxOptions merge(Capabilities capabilities) { super.merge(capabilities); if (capabilities instanceof FirefoxOptions) { Map options = (Map) capabilities.asMap().get("moz:firefoxOptions"); mergeArguments(options); mergeBooleanPrefs(capabilities); mergeIntPrefs(capabilities); mergeStringPrefs(capabilities); mergeLogLevel(capabilities); } return this; }

Target:
Generics, please!
Source:
public void merge(GridHubConfiguration other) { super.merge(other); if (other.jettyMaxThreads != null) jettyMaxThreads = other.jettyMaxThreads; capabilityMatcher = other.capabilityMatcher; if (other.newSessionWaitTimeout != null) newSessionWaitTimeout = other.newSessionWaitTimeout; if (other.prioritizer != null) prioritizer = other.prioritizer; if (other.throwOnCapabilityNotPresent != throwOnCapabilityNotPresent) throwOnCapabilityNotPresent = other.throwOnCapabilityNotPresent; }

Target:
There should be an `@Override` annotation here. Most IDEs will be busy freaking out at you, and some java versions won't compile the code.
Source:
private static Optional<Extension> loadCustomExtension() { String xpiProperty = System.getProperty(FirefoxDriver.SystemProperty.DRIVER_XPI_PROPERTY); if (xpiProperty != null && !xpiProperty.equals("")) { File xpi = new File(xpiProperty); return Optional.of((Extension) new FileExtension(xpi)); } return Optional.absent(); }

Target:
instead of empty string, we probably should check that the File exists (next line down). Then log a warning if it doesn't and continue otherwise.
Source:
public TkWithAliasHeader(final Base base, final Take take) { this.base = base; this.take = take; this.header = String.format("%s: %s", "X-Netbout-Alias", "%s"); }

Target:
@kujtimiihoxha Why not just `"X-Netbout-Alias: %s"` ?
Source:
public int allocate() throws IOException { synchronized (Ports.class) { int attempts = 0; int prt; do { prt = random(); ++attempts; // @checkstyle MagicNumber (1 line) if (attempts > 100) { throw new IllegalStateException( String.format( "failed to allocate TCP port after %d attempts", attempts ) ); } } while (Ports.ASSIGNED.contains(prt)); return prt; } }

Target:
@danff should be declared `static`
Source:
private Ports() { super(); }

Target:
@danff do we need to call `super()` here?
Source:
private static RqRegex request(final String code) throws Exception { return new RqRegex.Fake( PATTERN, URLEncoder.encode(TkEmVerifyTest.ENC.encrypt(code), "UTF-8") ); }

Target:
@kujtimiihoxha statics should be prependended with class name, so here it should be TkEmVerifyTest.PATTERN
Source:
public void rendersPage() throws Exception { final Base base = new MkBase(); final String alias = "test"; final String urn = "urn:test:1"; base.user(URN.create(urn)).aliases().add(alias); MatcherAssert.assertThat( new RsPrint( new TkIndex(base).act( new RqWithHeader( new RqWithAuth(urn), "Accept", "text/xml" ) )).printBody(), XhtmlMatchers.hasXPaths( "/page/alias/email", "/page/links/link[@rel='save-email']/@href" ) ); }

Target:
@exper0 let's move the final `).printBody(),` to the next line to maintain correct indentation.
Source:
public void throwsExceptionIfUnknownAliasKicked() throws Exception { final Inbox inbox = this.rule.get().aliases() .iterate().iterator().next().inbox(); final Bout bout = inbox.bout(inbox.start()); final String friend = "jim"; bout.friends().kick(friend); }

Target:
@dmzaytsev All variables here are still single-use variables, we can inline everything (i.e. make the whole test a single statement).
Source:
private static String generateAuthenticateHead( final String user, final String pass ) { final String auth = String.format("%s:%s", user, pass); final String encoded = DatatypeConverter.printBase64Binary( auth.getBytes() ); return String.format("Authorization: Basic %s", encoded); }

Target:
@dmzaytsev let's inline this
Source:
public void post(final String text) throws IOException { this.origin.post(text); for (final Friend friend : this.bout.friends().iterate()) { if (friend.email().isEmpty() || this.self == friend.alias()) { continue; } this.email(friend, text); } }

Target:
@ndbroadbent use `.equals` here.
Source:
public void updateItem(T item) { mAlgorithm.lock(); try { mAlgorithm.updateItem(item); } finally { mAlgorithm.unlock(); } }

Target:
Thoughts on returning a bool here? It could be helpful to know if an item you are trying to update was actually updated or not (and if not, can signal to the developer that they need to implement equals and hashcode).
Source:
public boolean addItems(Collection<T> items) { boolean result; mAlgorithm.lock(); try { result = mAlgorithm.addItems(items); } finally { mAlgorithm.unlock(); } return result; }

Target:
The `result` variable is not needed—the block within `finally` will still be invoked even after a `return`.
Source:
static XmlPullParser createParser(@IdRes int res) throws XmlPullParserException, IOException { InputStream stream = InstrumentationRegistry.getInstrumentation() .getTargetContext() .getResources() .openRawResource(res); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser parser = factory.newPullParser(); parser.setInput(stream, null); parser.next(); return parser; }

Target:
Why does `next` have to be invoked here?
Source:
/* package */ void setFillColor(String color) { // Tolerate KML with leading or trailing whitespace in colors color = color.trim(); // Add # to allow for mOutline color to be parsed correctly int polygonColorNum = (Color.parseColor("#" + convertColor(color))); setPolygonFillColor(polygonColorNum); mStylesSet.add("fillColor"); }

Target:
How about applying this method inside `convertColor` to avoid duplication and to make sure the same input sanitation is applied? Looks like in all cases `color.trim()` is desired before calling `convertColor` anyway.
Source:
private void removePlacemarks(HashMap<? extends Feature, Object> placemarks) { // Remove map object from the map super.removeFeatures((HashMap<Feature, Object>) placemarks); }

Target:
`super` reference can be removed here, as `removeFeatures()` is static.
Source:
public final static byte[] decode(byte[] sArr, int sOff, int sLen) throws DecodeException { try { return doDecode(sArr, sOff, sLen); } catch (Exception e) { throw new DecodeException(e); } }

Target:
is RuntimeException enough?
Source:
public BinaryBlockWriter(OutputStream out, Class<M> protoClass, BinaryConverter<M> binaryConverter, int numRecordsPerBlock) { out_ = out; numRecordsPerBlock_ = numRecordsPerBlock; innerClass_ = protoClass; binaryConverter_ = binaryConverter; protoBlobs_ = new ArrayList<ByteString>(numRecordsPerBlock_); }

Target:
Do you need this to become public? looks like you have a new public one below?
Source:
public LzoGenericB64LineRecordReader(TypeRef<M> typeRef, BinaryConverter<M> converter) { super(typeRef, new GenericWritable<M>(converter), converter); LOG.info("record type is " + typeRef.getRawClass()); }

Target:
Don't think this adds anything anymode, the typeRef will just be the convertors creator. I'd just kill the log line
Source:
public LzoGenericBlockRecordReader(TypeRef<M> typeRef, BinaryConverter<M> binaryConverter) { super(typeRef, new BinaryBlockReader(null, binaryConverter), new GenericWritable<M>(binaryConverter)); LOG.info("LzoGenericBlockRecordReader, type args are " + typeRef.getRawClass()); }

Target:
kill
Source:
public boolean readProtobuf(ProtobufWritable<M> message) throws Exception { return readNext(message); }

Target:
Exception is super generic and is usually an anti-pattern. Any reason for this change?
Source:
public RecordReader createRecordReader( InputSplit inputSplit, TaskAttemptContext taskAttemptContext) throws IOException { Configuration conf = HadoopCompat.getConfiguration(taskAttemptContext); initInputFormat(conf); if (shouldCombine(conf)) { return new CompositeRecordReader(delegate); } else { try { return delegate.createRecordReader(inputSplit, taskAttemptContext); } catch (InterruptedException e) { LOG.error("Thread interrupted", e); Thread.currentThread().interrupt(); throw new IOException(e); } } }

Target:
you can just ``` } catch (InterruptedException e) { throw new IOException(e); } ``` Throwing an exception is the right answer here but there's no point setting the thread interrupt flag. See: http://docs.oracle.com/javase/7/docs/api/java/lang/InterruptedException.html "Thrown when a thread is waiting, sleeping, or otherwise occupied, and the thread is interrupted, either before or during the activity. Occasionally a method may wish to test whether the current thread has been interrupted, and if so, to immediately throw this exception. The following code can be used to achieve this effect: if (Thread.interrupted()) // Clears interrupted status! throw new InterruptedException(); "
Source:
private static <T extends InputSplit> T deserializeInputSplitInternal( Configuration conf, DataInputStream in, Class<T> clazz) throws IOException { T split = ReflectionUtils.newInstance(clazz, conf); SerializationFactory factory = new SerializationFactory(conf); Deserializer<T> deserializer = factory.getDeserializer(clazz); deserializer.open(new UncloseableDataInputStream((DataInputStream) in)); return deserializer.deserialize(split); }

Target:
you have several layers of wrapping into UncloseableDataInputStream if not one. It looks like it should be done only once in this method.
Source:
public RecordWriter<K, V> getRecordWriter(FileSystem ignored, JobConf job, String name, Progressable progress) throws IOException { if (wrapped.realOutputFormat instanceof WorkFileOverride) { ((WorkFileOverride) wrapped.realOutputFormat).setName(name); } return wrapped.getRecordWriter(ignored, job, name, progress); }

Target:
right, I meant we could do this in DeprecatedOutputFormatWrapper. I agree, we can't avoid an interface like WorkFileOverride, since we can't really override getDefaultWorkFile for given _object_ ('realOutputFormat' in this case).
Source:
public static void setRequiredFieldConf(Configuration conf, RequiredFieldList requiredFieldList) { // set required fields conf for RCFile[Protobuf|Thrift] input format if (requiredFieldList != null) { List<Integer> indices = Lists.newArrayList(); for(RequiredField f : requiredFieldList.getFields()) { indices.add(f.getIndex()); } conf.set(RCFileUtil.REQUIRED_FIELD_INDICES_CONF, Joiner.on(",").join(indices)); } else { conf.set(RCFileUtil.REQUIRED_FIELD_INDICES_CONF, ""); } }

Target:
prefer: ``` String value = ""; if (requiredFieldList != null) { List<Integer> indices = Lists.newArrayList(); for(RequiredField f : requiredFieldList.getFields()) { indices.add(f.getIndex()); } value = Joiner.on(",").join(indices); } conf.set(RCFileUtil.REQUIRED_FIELD_INDICES_CONF, value); ```
Source:
public static void setConversionProperties(Configuration conf) { if (conf != null) { useEnumId = conf.getBoolean(USE_ENUM_ID_CONF_KEY, false); LOG.info("useEnumId is set to " + useEnumId); } }

Target:
can you make this a debug log? It would be easy to see if this config does not take affect. Pig creates multiple of these loaders and we will see lots of these in the log.
Source:
public void initialize(Configuration conf, Properties tbl) throws SerDeException { try { String className = tbl .getProperty(org.apache.hadoop.hive.serde.Constants.SERIALIZATION_CLASS); protobufClass = conf.getClassByName(className).asSubclass(Message.class); protobufConverter = ProtobufConverter.newInstance(new TypeRef<Message>(protobufClass){}); } catch (Exception e) { throw new SerDeException(e); } }

Target:
Nit - import Constants so this all fits on one line.
Source:
protected void skipToNextSyncPoint(boolean atFirstRecord) throws IOException { // No need to skip to the sync point here; the block reader will do it for us. LOG.debug("LzoProtobufBlockRecordReader.skipToNextSyncPoint called with atFirstRecord = " + atFirstRecord); updatePosition = !atFirstRecord; LOG.debug("reset first record offset in skipToNextSyncPoint()"); }

Target:
there is already a debug message above.
Source:
private Map<String,Object> walkJson(JSONObject jsonObj) { Map<String,Object> v = Maps.newHashMap(); for (Object key: jsonObj.keySet()) { if (fields == null || fields.contains(key.toString())) v.put(key.toString(), wrap(jsonObj.get(key))); } return v; }

Target:
thanks. Let us know one this is ready to go. btw, you could skip map copy in the common case where no fields are set.
Source:
protected BinaryBlockReader(InputStream in, BinaryConverter<M> protoConverter, boolean skipEmptyRecords) { in_ = in; protoConverter_ = protoConverter; skipEmptyBlobs = skipEmptyRecords; searcher_ = new StreamSearcher(Protobufs.KNOWN_GOOD_POSITION_MARKER); }

Target:
what's the difference between blobs and records? why use 2 terms?
Source:
public JsonLoader(String inputFormatClassName) { this.inputFormatClassName = inputFormatClassName; try { this.inputFormat = (FileInputFormat) Class.forName(inputFormatClassName).newInstance(); } catch (InstantiationException e) { throw new RuntimeException("Failed creating input format " + inputFormatClassName, e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed creating input format " + inputFormatClassName, e); } catch (ClassNotFoundException e) { throw new RuntimeException("Failed creating input format " + inputFormatClassName, e); } }

Target:
should be moved to getInputFormat(). need to use PigContext.resolveClasName() for Pig loaders.
Source:
public InputFormat getInputFormat() throws IOException { if (inputFormat != null) { return inputFormat; } else { try { inputFormat = (FileInputFormat) PigContext.resolveClassName(inputFormatClassName).newInstance(); return inputFormat; } catch (InstantiationException e) { throw new IOException("Failed creating input format " + inputFormatClassName, e); } catch (IllegalAccessException e) { throw new IOException("Failed creating input format " + inputFormatClassName, e); } } }

Target:
This could just return (InputFormat) PigContext.resolveClassName(inputFormatName).newInstance(); resolveClassName throws only IOException.
Source:
public void onPause() { super.onPause(); if (getAllowStartStopFromHeadsetKey()) { unregisterHeadsetListener(); } unRegisterStartStopListener(); }

Target:
isn't this the same bug that you had before, that headset wasn't working while app was minimized ?
Source:
private boolean matchesAnyCookieName(String cookieString, String... cookieNames) { //noinspection SimplifiableIfStatement if (StringUtils.isEmpty(cookieString) || ArrayUtils.isEmpty(cookieNames)) { return false; } return Arrays.stream(cookieNames).anyMatch(name -> matchesCookieName(cookieString, name)); }

Target:
Why this separate `if` statement and not just `return isEmpty(cookieString) || isEmpty(cookieNames) || Arrays.stream(...`?
Source:
public void stop(@Nonnull Throwable cause) throws Exception { if (body!=null) body.cancel(cause); }

Target:
can you enclose this in `{ }` ;
Source:
public SequenceReader(List<? extends Reader> readers) { int size = readers.size(); fReaders = new Reader[size]; for (int i = 0; i < size; i++) { fReaders[i] = readers.get(i); } }

Target:
@RobberPhex If you make the input a `Collection`, then you can take a `Set` as input. You should also consider using a List internally instead of an array. It might make the above simpler.
Source:
public void copyDirectoryToDirectoryThrowsIllegalExceptionWithCorrectMessageWhenSrcDirIsNotDirectory() throws IOException { File srcDir = temporaryFolder.newFile("notadirectory"); File destDir = temporaryFolder.newFolder("destinationDirectory"); String expectedMessage = String.format("Source '%s' is not a directory", srcDir); assertExceptionTypeAndMessage(srcDir, destDir, IllegalArgumentException.class, expectedMessage); }

Target:
Use `final` where possible.
Source:
private static boolean isValidHostName(String name) { return isIPv4Address(name) || isIPv6Address(name) || isRFC3986HostName(name); }

Target:
isIPv4Address can return false for input that looks like an IP address but fails a subsequent check, e.g. 999.9.9.9. In which case it will be subject to two further checks (which must fail if the code is correct).
Source:
protected ExpectedBehaviour getExpectedBehaviour() { return excNumberDefined ? ExpectedBehaviour.SPECIFIC_EXCEPTION : ExpectedBehaviour.ANY_EXCEPTION; }

Target:
Yes, it looks good now. What do you mean by min number of references? (In general I think we have a Checkstyle will raise an error if we have unused imports).
Source:
abstract protected ResultSet getColumns() throws SQLException; public Map<String, DbParameterAccessor> getParams() throws SQLException { Map<String, DbParameterAccessor> allParams = new HashMap<String, DbParameterAccessor>(); try (ResultSet rs = getColumns()) { while (rs.next()) { DbParameterAccessor accessor = createColumnAccessor(rs); allParams.put(normaliseName(accessor.getName()), accessor); } } return allParams; }

Target:
Should be fine to call `new HashMap<>()` here, no need to list types on the right side (I think we already did that somewhere).
Source:
public void connect(String connectionString, Properties info) throws SQLException { registerDriver(); if (currentConnection != null) { closeConnection(); } currentConnection = DriverManager.getConnection(connectionString, info); afterConnectionEstablished(); }

Target:
No need of that `null` check here - `closeConnection()` already takes care about that.
Source:
public static String normaliseName(final String name) { if (name == null) { return ""; } if (isEscaped(name)) { return name.substring(1,name.length() - 1).replace("\"\"", "\""); } return dbfit.util.NameNormaliser.normaliseName(name); }

Target:
Missing space after `1`.
Source:
public static Object normaliseValue(Object currVal) throws SQLException { if (currVal==null) return null; TypeTransformer tn=TypeNormaliserFactory.getNormaliser(currVal.getClass()); if (tn!=null) currVal=tn.transform(currVal); return currVal; }

Target:
As we're anyway touching these lines, let's reformat and add space around `=` and `!=`.
Source:
public void run() throws SQLException { ResultSet rs = statement.executeQuery(); try { rs.next(); returnValue = rs.getObject(1); } finally { rs.close(); } }

Target:
In other places we've been using [try with resources syntax](https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html). Might be appropriate here too?
Source:
public void afterConnectionEstablished() throws SQLException { TypeAdapter.registerParseDelegate(java.math.BigDecimal.class, new dbfit.util.BigDecimalParseDelegate()); if (currentConnection.getMetaData().supportsTransactions()) { Options.setOption(Options.OPTION_AUTO_COMMIT, "false"); currentConnection.setAutoCommit(false); } else { Options.setOption(Options.OPTION_AUTO_COMMIT, "true"); currentConnection.setAutoCommit(true); } }

Target:
Looks like this `registerParseDelegate` call is already present in `FitNesseTestHost`. Do we need it here again?
Source:
public StatementExecution toStatementExecution() throws SQLException { System.out.println("DbStoredProcedureCall: toStatementExecution"); StatementExecution cs = new StatementExecution( this.environment.getConnection().prepareCall(toSqlString()), isFunction() ? this.environment.functionReturnValueViaResultSet() : false, isFunction() ? this.environment.discountFunctionReturnValueParameter() : false); bindParametersTo(cs); return cs; }

Target:
Do we need that `System.out.println`?
Source:
public void setObject(int index, Object value, int sqlType) throws SQLException { if (value == null) statement.setNull(index, sqlType); else // Don't use the variant that takes sqlType. // Derby (at least) assumes no decimal places for Types.DECIMAL and truncates the source data. statement.setObject(index, value); }

Target:
The general convention is to use `{}` braces in if/else statements.
Source:
public StatementExecution buildPreparedStatement() throws SQLException { return new StatementExecution(environment.createStatementWithBoundFixtureSymbols(testHost, statementText), false, environment.supportsSavepoints()); }

Target:
These SavePoints are bringing some noise here. There was a discussion in #211 about removing them: if we do that, we could simplify the changes here.
Source:
public void doTable(Parse table) { super.doTable(table); if (counts.wrong == 0 && counts.exceptions == 0) { table.parts.last().more = getSummary(); } }

Target:
what's the thinking behind only showing this when everything's OK? Is there a particular reason why we don't want to show the summary when matching fails?
Source:
private IProject getProject(final IJavaElementDelta delta) { final IJavaProject javaProject = delta.getElement().getJavaProject(); if (javaProject != null) { return javaProject.getProject(); } // carry on with children elements. for (IJavaElementDelta affectedChild : delta.getAffectedChildren()) { return getProject(affectedChild); } // if no child return null; }

Target:
so you're returning something on the very first iteration. Not sure of the consequences of that.
Source:
public void indexMarker(final IMarker marker) { try { Logger.traceIndexing("Indexing after addition...", marker); final Document doc = LuceneDocumentFactory.createDocument(marker); Logger.debugIndexing("Adding Marker into index with following fields: {}", doc.getFields()); indexWriter.addDocument(doc); indexWriter.commit(); } catch (Exception e) { Logger.error("Failed to index the JAX-RS Endpoint " + marker, e); } finally { Logger.traceIndexing(" Done indexing {}.", marker); } }

Target:
Could specific exception be used here?
Source:
private static boolean isMessageContinue(@NotNull String messagePart) { return Character.isWhitespace(messagePart.charAt(0)); }

Target:
This is dangerous. You're not 100% sure you're not given an empty message here, yet you call charAt(0).
Source:
private Boolean calcNoAutoImportAll() { return containsCompileDirectiveWithOption("no_auto_import"); }

Target:
Please check how it works with 'quoted' names.
Source:
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { ErlangFunctionCallExpression callExpr = PsiTreeUtil.getParentOfType( descriptor.getPsiElement(), ErlangFunctionCallExpression.class); if (callExpr == null) return; callExpr.replace(ErlangElementFactory.createFunctionWithModuleCallExpression(project, myModuleName, callExpr.getText())); }

Target:
Invert if statement please.
Source:
public void testCommon() throws Throwable { doTest("Remove from import"); }

Target:
throws Throwable?
Source:
private static List<String> replaceElementsSuffix(List<String> bcp, String originalSuffix, String newSuffix) { for (int i=0; i<bcp.size(); i++) { String entry = bcp.get(i); if (entry.endsWith(originalSuffix)) { bcp.set(i, entry.substring(0, entry.length() - 4) + newSuffix); } } return bcp; }

Target:
entry.length() - originalSuffix.length()
Source:
public Collection<LabelItem> getLabels() { return new ArrayList<LabelItem>(labels); }

Target:
if Getter returns a Collection, why this creates ArrayList first?
Source:
protected void log(final Level level, final String msg) { this.logger.log(level, this.simpleName + " " + msg); }

Target:
warning: The static field AbstractProcessor.logger should be accessed in a static way.
Source:
public Map<StoreKey, MessageInfo> findKeys(List<? extends StoreKey> storeKeys) throws StoreException { Map<StoreKey, MessageInfo> messageInfoMap = new HashMap<>(); for (StoreKey storeKey : storeKeys) { // TODO: Need to look into the possibility if its more efficient to not call findKey() multiple times in a loop, // and instead search the index once for all the blobs in the list. try { messageInfoMap.put(storeKey, findKey(storeKey)); } catch (StoreException e) { logger.error("findKey failed for key with reason {}", storeKey.getID(), e.getErrorCode().toString()); } } return messageInfoMap; }

Target:
This method doesn't throw out StoreException.
Source:
public boolean hasPrevious() { return cursor != 0; }

Target:
why not `cursor > 0` ?
Source:
CompactionDetails getCompactionDetails(BlobStore blobStore) throws StoreException { ReplicaId replicaId = blobStore.getReplicaId(); if (compactionPolicyFactory != null && compactionPolicyFactory instanceof HybridCompactionPolicyFactory) { CompactionPolicyCounter compactionPolicyCounter = replicaToCounterMap.getOrDefault(replicaId, new CompactionPolicyCounter(storeConfig)); compactionPolicyCounter.increment(); replicaToCounterMap.put(replicaId, compactionPolicyCounter); } return blobStore.getCompactionDetails(compactionPolicy, replicaToCounterMap.get(replicaId)); }

Target:
we actually don't have to differentiate the compaction policy factory when creating and incrementing the couter. We can just increment it for every policy.
Source:
public void sendResponse(Send payloadToSend, NetworkRequest originalRequest, ServerNetworkResponseMetrics metrics) throws InterruptedException { if (!(originalRequest instanceof NettyServerRequest)) { throw new IllegalArgumentException("NetworkRequest should be NettyRequest"); } ChannelHandlerContext ctx = ((NettyServerRequest) originalRequest).getCtx(); http2ServerMetrics.requestTotalProcessingTime.update( System.currentTimeMillis() - originalRequest.getStartTimeInMs()); ctx.pipeline().writeAndFlush(payloadToSend); }

Target:
ctx.writeAndFlush would do the work. By the way, maybe we can do `ctx.isOpen` check before we write, it, the connection might be closed before server got a chance to write.
Source:
public ChannelHandlerContext getCtx() { return ctx; }

Target:
package-private?
Source:
public Http2MultiplexedChannelPool(InetSocketAddress inetSocketAddress, SSLFactory sslFactory, EventLoopGroup eventLoopGroup, Http2ClientConfig http2ClientConfig, Http2ClientMetrics http2ClientMetrics, ChannelInitializer streamChannelInitializer) { this(new SimpleChannelPool(createBootStrap(eventLoopGroup, http2ClientConfig, inetSocketAddress), new Http2ChannelPoolHandler(sslFactory, inetSocketAddress.getHostName(), inetSocketAddress.getPort(), http2ClientConfig)), eventLoopGroup, ConcurrentHashMap.newKeySet(), inetSocketAddress, new Http2ClientConfig(new VerifiableProperties(new Properties())), http2ClientMetrics, streamChannelInitializer); }

Target:
why is the http2ClientConfig passed in from the constructor not used here?
Source:
public InMemoryStore getStore(PartitionId partitionId) { return storesByPartition.get(partitionId); }

Target:
same here, can be package private
Source:
public void validateRequest(RestRequest restRequest, Callback<Void> callback) { Exception exception = null; serverMetrics.securityServiceValidateRequestRate.mark(); long startTimeMs = System.currentTimeMillis(); if (!isOpen) { exception = new RestServiceException("ServerSecurityService is closed", RestServiceErrorCode.ServiceUnavailable); } else if (restRequest == null) { throw new IllegalArgumentException("restRequest is null"); } serverMetrics.securityServiceValidateRequestTimeInMs.update(System.currentTimeMillis() - startTimeMs); callback.onCompletion(null, exception); }

Target:
Remove timer.
Source:
public PartitionLeaderInfo(StoreManager storeManager) { peerLeaderReplicasByPartition = new ConcurrentHashMap<>(); this.storeManager = storeManager; }

Target:
minor: can remove this and directly initialize it at line 41
Source:
void addToCache(String blobKey, short lifeVersion, BlobState blobState) { if (isVcr) { if (blobState == BlobState.TTL_UPDATED) { // In case of ttl update we update the ttl without taking into account the life version. // So make sure that we do not decrease the lifeVersion in cache due to an incoming ttl update. if (recentBlobCache.containsKey(blobKey)) { lifeVersion = (lifeVersion > recentBlobCache.get(blobKey).getLifeVersion()) ? lifeVersion : recentBlobCache.get(blobKey).getLifeVersion(); } } recentBlobCache.put(blobKey, new BlobLifeState(blobState, lifeVersion, recentBlobCache.get(blobKey))); } }

Target:
Can this just be Math.max(lifeVersion, recentBlobCache.get(blobKey).getLifeVersion()) ?
Source:
private static boolean hasReachedAnyLocalQuorum(Map<String, Integer> totalNumberInDcs, Map<String, Integer> currentNumberInDcs) { for (String dcName : totalNumberInDcs.keySet()) { int totalNum = totalNumberInDcs.get(dcName); if (currentNumberInDcs.containsKey(dcName)) { int currentNum = currentNumberInDcs.get(dcName); if (totalNum != 1 && currentNum > totalNum / 2) { return true; } } } return false; }

Target:
same question here, do we account for the colo with single replica?
Source:
public static boolean isPossibleClientTermination(Throwable cause) { if (cause instanceof SSLException) { return SSL_ENGINE_CLOSED_EXCEPTION_MSG.equals(cause.getMessage()); } else if (cause instanceof IOException) { return CLIENT_RESET_EXCEPTION_MSG.equals(cause.getMessage()) || CLIENT_BROKEN_PIPE_EXCEPTION_MSG.equals( cause.getMessage()); } else { return false; } }

Target:
Actually SSLException is an IOException, so we don't have to do this if-else statement.
Source:
public IndexEntry next() { try { StoreKey key = getKeyAt(mmap, currentIdx); mmap.get(valueBuf); return new IndexEntry(key, new IndexValue(startOffset.getName(), ByteBuffer.wrap(valueBuf), getVersion())); } catch (Exception e) { logger.error("Failed to read index entry at " + currentIdx, e); } finally { currentIdx++; } return null; }

Target:
This will cause NullPointException if it failed to read index. Is this intended?
Source:
public Map<String, List<ReplicaId>> getPeerLeaderReplicasByPartition() { return Collections.unmodifiableMap(peerLeaderReplicasByPartition); }

Target:
This can be package private. Also add java doc to this method please.
Source:
public void onPartitionBecomeLeaderFromStandby(String partitionName) { try { PartitionStateChangeListener cloudToStoreReplicationListener = partitionStateChangeListeners.get(StateModelListenerType.CloudToStoreReplicationManagerListener); if (cloudToStoreReplicationListener != null) { cloudToStoreReplicationListener.onPartitionBecomeLeaderFromStandby(partitionName); } } catch (Exception e) { participantMetrics.standbyCount.addAndGet(-1); participantMetrics.errorStateCount.addAndGet(1); throw e; } participantMetrics.standbyCount.addAndGet(-1); participantMetrics.leaderCount.addAndGet(1); }

Target:
see above about finally.