Skip to content

Commit

Permalink
[Truffle] Fix a few issues detected by FindBugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Sep 29, 2016
1 parent 427fc50 commit 8b406d5
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 46 deletions.
Expand Up @@ -131,7 +131,7 @@ public byte[] formatInfinite(int width, int precision, double dval) {
return buf.bytes();
}

final Locale locale = Locale.getDefault(); // TODO BJF Aug 13, 2016 Correct locale here?
final Locale locale = Locale.ENGLISH;
NumberFormat nf = Sprintf.getNumberFormat(locale);
nf.setMaximumFractionDigits(Integer.MAX_VALUE);
String str = nf.format(dval);
Expand Down Expand Up @@ -161,10 +161,8 @@ public byte[] formatInfinite(int width, int precision, double dval) {
case '7':
case '8':
case '9':
if (nTrailingZeroes > 0) {
for (; nTrailingZeroes > 0; nTrailingZeroes--) {
digits[nDigits++] = '0';
}
for (; nTrailingZeroes > 0; nTrailingZeroes--) {
digits[nDigits++] = '0';
}
digits[nDigits++] = ival;
break; // switch
Expand Down Expand Up @@ -192,10 +190,8 @@ public byte[] formatInfinite(int width, int precision, double dval) {
case '7':
case '8':
case '9':
if (nTrailingZeroes > 0) {
for (; nTrailingZeroes > 0; nTrailingZeroes--) {
digits[nDigits++] = '0';
}
for (; nTrailingZeroes > 0; nTrailingZeroes--) {
digits[nDigits++] = '0';
}
digits[nDigits++] = ival;
break; // switch
Expand Down
Expand Up @@ -41,7 +41,7 @@ public class PrintfSimpleTreeBuilder {
private final List<FormatNode> sequence = new ArrayList<>();
private final List<SprintfConfig> configs;

public static int DEFAULT = -1;
public static final int DEFAULT = -1;

private static final byte[] EMPTY_BYTES = new byte[]{};

Expand Down
Expand Up @@ -131,35 +131,18 @@ public static String decodeRope(Rope value) {

value = flatten(value);

if (value instanceof LeafRope) {
int begin = 0;
int length = value.byteLength();
int begin = 0;
int length = value.byteLength();

Encoding encoding = value.getEncoding();
Encoding encoding = value.getEncoding();

if (encoding == UTF8Encoding.INSTANCE) {
return RubyEncoding.decodeUTF8(value.getBytes(), begin, length);
}

Charset charset = encodingToCharsetMap.get(encoding);

if (charset == null) {
charset = EncodingManager.charsetForEncoding(encoding);
encodingToCharsetMap.put(encoding, charset);
}
if (encoding == UTF8Encoding.INSTANCE) {
return RubyEncoding.decodeUTF8(value.getBytes(), begin, length);
}

if (charset == null) {
try {
return new String(value.getBytes(), begin, length, encoding.toString());
} catch (UnsupportedEncodingException uee) {
return value.toString();
}
}
Charset charset = encodingToCharsetMap.computeIfAbsent(encoding, EncodingManager::charsetForEncoding);

return RubyEncoding.decode(value.getBytes(), begin, length, charset);
} else {
throw new RuntimeException("Decoding to String is not supported for rope of type: " + value.getClass().getName());
}
return RubyEncoding.decode(value.getBytes(), begin, length, charset);
}

// MRI: get_actual_encoding
Expand Down
Expand Up @@ -1949,7 +1949,7 @@ private Object performSqueezeBang(DynamicObject string, DynamicObject[] otherStr

if (checkEncodingNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
checkEncodingNode = insert(checkEncodingNode = EncodingNodesFactory.CheckEncodingNodeGen.create(getContext(), null, null, null));
checkEncodingNode = insert(EncodingNodesFactory.CheckEncodingNodeGen.create(getContext(), null, null, null));
}

final Rope rope = rope(string);
Expand Down Expand Up @@ -4394,7 +4394,7 @@ private DynamicObject makeBuffer(DynamicObject string, int beg, int len) {
return ret;
}

private final class SearchResult {
private static final class SearchResult {
public final int index;
public final Rope rope;

Expand Down
Expand Up @@ -34,7 +34,7 @@ public Object findExportedObject(String name) {
}

public Object importObject(String name) {
return context.getEnv().importSymbol(name.toString());
return context.getEnv().importSymbol(name);
}

}
Expand Up @@ -21,7 +21,6 @@ public class ReadBlockNode extends RubyNode {
private final Object valueIfAbsent;

private final ConditionProfile nullProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile unusualShapeProfile = ConditionProfile.createBinaryProfile();

public ReadBlockNode(Object valueIfAbsent) {
this.valueIfAbsent = valueIfAbsent;
Expand Down
Expand Up @@ -24,8 +24,6 @@
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.MetaClassNode;
import org.jruby.truffle.language.objects.MetaClassNodeGen;

public class UncachedDispatchNode extends DispatchNode {

Expand All @@ -35,7 +33,6 @@ public class UncachedDispatchNode extends DispatchNode {
@Child private IndirectCallNode indirectCallNode;
@Child private ToSymbolNode toSymbolNode;
@Child private NameToJavaStringNode toJavaStringNode;
@Child private MetaClassNode metaClassNode;

private final BranchProfile methodMissingProfile = BranchProfile.create();
private final BranchProfile methodMissingNotFoundProfile = BranchProfile.create();
Expand All @@ -48,7 +45,6 @@ public UncachedDispatchNode(RubyContext context, boolean ignoreVisibility, Dispa
this.indirectCallNode = Truffle.getRuntime().createIndirectCallNode();
this.toSymbolNode = ToSymbolNodeGen.create(context, null, null);
this.toJavaStringNode = NameToJavaStringNode.create();
this.metaClassNode = MetaClassNodeGen.create(context, null, null);
}

@Override
Expand Down
Expand Up @@ -497,7 +497,7 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnParseNode node) {

final List<ParseNode> childNodes;

if (node.childNodes() == null || node.childNodes().get(0) == null) {
if (node.childNodes().get(0) == null) {
childNodes = Collections.emptyList();
} else {
childNodes = node.childNodes().get(0).childNodes();
Expand Down
Expand Up @@ -299,7 +299,7 @@ private void declareArguments() {
public static Arity getArity(ArgsParseNode argsNode) {
final String[] keywordArguments;

if (argsNode.hasKwargs() && argsNode.getKeywords() != null) {
if (argsNode.hasKwargs() && argsNode.getKeywordCount() > 0) {
final ParseNode[] keywordNodes = argsNode.getKeywords().children();
final int keywordsCount = keywordNodes.length;

Expand Down
Expand Up @@ -42,7 +42,7 @@ public static String replace(String string, CharSequence target, CharSequence re

@TruffleBoundary
public static String toLowerCase(String string) {
return string.toLowerCase();
return string.toLowerCase(Locale.ENGLISH);
}

}

0 comments on commit 8b406d5

Please sign in to comment.