Skip to content

Commit

Permalink
Showing 44 changed files with 171 additions and 194 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/BasicObjectStub.java
Original file line number Diff line number Diff line change
@@ -190,7 +190,7 @@ public static RubyString convertToString(IRubyObject self) {
public static IRubyObject anyToString(IRubyObject self) {
String cname = getMetaClass(self).getRealClass().getName();
/* 6:tags 16:addr 1:eos */
RubyString str = getRuntime(self).newString("#<" + cname + ":0x" + Integer.toHexString(System.identityHashCode(self)) + ">");
RubyString str = getRuntime(self).newString("#<" + cname + ":0x" + Integer.toHexString(System.identityHashCode(self)) + '>');
str.setTaint(isTaint(self));
return str;
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -2864,7 +2864,7 @@ public RubyModule getClassFromPath(String path) {

IRubyObject cc = c.getConstant(str);
if(!(cc instanceof RubyModule)) {
throw newTypeError("" + path + " does not refer to class/module");
throw newTypeError(path + " does not refer to class/module");
}
c = (RubyModule)cc;
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
@@ -701,8 +701,8 @@ protected static JRubyFile getDirForRmdir(final Ruby runtime, final String path)
// dir can't be read, so we check permissions first

// no permission
if (directory.getParentFile().exists() &&
!directory.getParentFile().canWrite()) {
File parentFile = directory.getParentFile();
if (parentFile.exists() && ! parentFile.canWrite()) {
throw runtime.newErrnoEACCESError(path);
}

21 changes: 12 additions & 9 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -353,11 +353,12 @@ public IRubyObject chmod(ThreadContext context, IRubyObject arg) {
checkClosed(context);
int mode = (int) arg.convertToInteger().getLongValue();

if (!new File(getPath()).exists()) {
throw context.runtime.newErrnoENOENTError(getPath());
final String path = getPath();
if ( ! new File(path).exists() ) {
throw context.runtime.newErrnoENOENTError(path);
}

return context.runtime.newFixnum(context.runtime.getPosix().chmod(getPath(), mode));
return context.runtime.newFixnum(context.runtime.getPosix().chmod(path, mode));
}

@JRubyMethod(required = 2)
@@ -373,11 +374,12 @@ public IRubyObject chown(ThreadContext context, IRubyObject arg1, IRubyObject ar
group = RubyNumeric.num2int(arg2);
}

if (!new File(getPath()).exists()) {
throw context.runtime.newErrnoENOENTError(getPath());
final String path = getPath();
if ( ! new File(path).exists() ) {
throw context.runtime.newErrnoENOENTError(path);
}

return context.runtime.newFixnum(context.runtime.getPosix().chown(getPath(), owner, group));
return context.runtime.newFixnum(context.runtime.getPosix().chown(path, owner, group));
}

@JRubyMethod
@@ -436,8 +438,9 @@ public static IRubyObject path(ThreadContext context, IRubyObject self, IRubyObj
@JRubyMethod(name = {"path", "to_path"})
public IRubyObject path(ThreadContext context) {
IRubyObject newPath = context.runtime.getNil();
if (getPath() != null) {
newPath = context.runtime.newString(getPath());
final String path = getPath();
if (path != null) {
newPath = context.runtime.newString(path);
newPath.setTaint(true);
}
return newPath;
@@ -1733,7 +1736,7 @@ public static String expandUserPath(ThreadContext context, String path, boolean
throw context.runtime.newArgumentError("user " + user + " does not exist");
}

path = "" + dir + (pathLength == userEnd ? "" : path.substring(userEnd));
path = dir + (pathLength == userEnd ? "" : path.substring(userEnd));

// getpwd (or /etc/passwd fallback) returns a home which is not absolute!!! [mecha-unlikely]
if (raiseOnRelativePath && !isAbsolutePath(path)) throw context.runtime.newArgumentError("non-absolute home of " + user);
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -2041,7 +2041,7 @@ public void clear() {
public boolean equals(Object other) {
if (!(other instanceof RubyHash)) return false;
if (this == other) return true;
return op_equal(getRuntime().getCurrentContext(), (RubyHash)other).isTrue() ? true : false;
return op_equal(getRuntime().getCurrentContext(), (RubyHash)other).isTrue();
}

@Override
31 changes: 12 additions & 19 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -4319,44 +4319,42 @@ public ByteList allocate(int size) {
protected IOOptions updateIOOptionsFromOptions(ThreadContext context, RubyHash options, IOOptions ioOptions) {
if (options == null || options.isNil()) return ioOptions;

Ruby runtime = context.runtime;
final Ruby runtime = context.runtime;

if (options.containsKey(runtime.newSymbol("mode"))) {
ioOptions = parseIOOptions(options.fastARef(runtime.newSymbol("mode")));
final RubySymbol mode = runtime.newSymbol("mode");
if (options.containsKey(mode)) {
ioOptions = parseIOOptions(options.fastARef(mode));
}

// This duplicates the non-error behavior of MRI 1.9: the
// :binmode option is ORed in with other options. It does
// not obliterate what came before.

if (options.containsKey(runtime.newSymbol("binmode")) &&
options.fastARef(runtime.newSymbol("binmode")).isTrue()) {

final RubySymbol binmode = runtime.newSymbol("binmode");
if (options.containsKey(binmode) && options.fastARef(binmode).isTrue()) {
ioOptions = newIOOptions(runtime, ioOptions, ModeFlags.BINARY);
}

// This duplicates the non-error behavior of MRI 1.9: the
// :binmode option is ORed in with other options. It does
// not obliterate what came before.

if (options.containsKey(runtime.newSymbol("binmode")) &&
options.fastARef(runtime.newSymbol("binmode")).isTrue()) {

if (options.containsKey(binmode) && options.fastARef(binmode).isTrue()) {
ioOptions = newIOOptions(runtime, ioOptions, ModeFlags.BINARY);
}

if (options.containsKey(runtime.newSymbol("textmode")) &&
options.fastARef(runtime.newSymbol("textmode")).isTrue()) {

final RubySymbol textmode = runtime.newSymbol("textmode");
if (options.containsKey(textmode) && options.fastARef(textmode).isTrue()) {
ioOptions = newIOOptions(runtime, ioOptions, ModeFlags.TEXT);
}

final RubySymbol open_args = runtime.newSymbol("open_args");
// TODO: Waaaay different than MRI. They uniformly have all opening logic
// do a scan of args before anything opens. We do this logic in a less
// consistent way. We should consider re-impling all IO/File construction
// logic.
if (options.containsKey(runtime.newSymbol("open_args"))) {
IRubyObject args = options.fastARef(runtime.newSymbol("open_args"));
if (options.containsKey(open_args)) {
IRubyObject args = options.fastARef(open_args);

RubyArray openArgs = args.convertToArray();

@@ -4669,11 +4667,6 @@ public IRubyObject getline(Ruby runtime, ByteList separator, long limit) {
return getline(runtime.getCurrentContext(), runtime.newString(separator), limit, null);
}

@Deprecated
private IRubyObject getline(ThreadContext context, IRubyObject separator, ByteListCache cache) {
return getline(context, separator, -1, cache);
}

@Deprecated
public IRubyObject getline(ThreadContext context, ByteList separator) {
return getline(context, RubyString.newString(context.runtime, separator), -1, null);
8 changes: 5 additions & 3 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -552,7 +552,8 @@ private String calculateName() {
private String calculateAnonymousName() {
if (anonymousName == null) {
// anonymous classes get the #<Class:0xdeadbeef> format
StringBuilder anonBase = new StringBuilder("#<" + metaClass.getRealClass().getName() + ":0x");
StringBuilder anonBase = new StringBuilder(24);
anonBase.append("#<").append(metaClass.getRealClass().getName()).append(":0x");
anonBase.append(Integer.toHexString(System.identityHashCode(this))).append('>');
anonymousName = anonBase.toString();
}
@@ -1163,8 +1164,9 @@ public void removeMethod(ThreadContext context, String name) {

// We can safely reference methods here instead of doing getMethods() since if we
// are adding we are not using a IncludedModule.
synchronized(methodLocation.getMethodsForWrite()) {
DynamicMethod method = (DynamicMethod) methodLocation.getMethodsForWrite().remove(name);
Map<String, DynamicMethod> methodsForWrite = methodLocation.getMethodsForWrite();
synchronized (methodsForWrite) {
DynamicMethod method = (DynamicMethod) methodsForWrite.remove(name);
if (method == null) {
throw runtime.newNameError("method '" + name + "' not defined in " + getName(), name);
}
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/RubyProc.java
Original file line number Diff line number Diff line change
@@ -211,13 +211,14 @@ public IRubyObject to_s() {

@JRubyMethod(name = "to_s", alias = "inspect")
public IRubyObject to_s19() {
StringBuilder sb = new StringBuilder("#<Proc:0x" + Integer.toString(block.hashCode(), 16));
String file = block.getBody().getFile();
StringBuilder sb = new StringBuilder(32);
sb.append("#<Proc:0x").append(Integer.toString(block.hashCode(), 16));

String file = block.getBody().getFile();
if (file != null) sb.append('@').append(file).append(':').append(block.getBody().getLine() + 1);

if (isLambda()) sb.append(" (lambda)");
sb.append(">");
sb.append('>');

IRubyObject string = RubyString.newString(getRuntime(), sb.toString());

34 changes: 17 additions & 17 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -2129,7 +2129,7 @@ public RubyString concat19(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFixnum) {
long c = RubyNumeric.num2long(other);
if (c < 0) {
throw runtime.newRangeError("" + c + " out of char range");
throw runtime.newRangeError(c + " out of char range");
}
return concatNumeric(runtime, (int)(c & 0xFFFFFFFF));
} else if (other instanceof RubyBignum) {
@@ -3715,19 +3715,21 @@ private static IRubyObject scanOnce(ThreadContext context, RubyString str, IRuby

if (patternSearch(context, pat, str, startp[0], true) >= 0) {
match = (RubyMatchData)context.getBackRef();
if (match.begin(0) == match.end(0)) {
final int matchEnd = match.end(0);
if (match.begin(0) == matchEnd) {
Encoding enc = str.getEncoding();
/*
* Always consume at least one character of the input string
*/
if (str.size() > match.end(0)) {
startp[0] = match.end(0) + encFastMBCLen(str.value.unsafeBytes(), str.value.begin() + match.end(0),
str.value.begin() + str.value.realSize(), enc);
if (str.size() > matchEnd) {
final ByteList strValue = str.value;
startp[0] = matchEnd + encFastMBCLen(strValue.unsafeBytes(), strValue.begin() + matchEnd,
strValue.begin() + strValue.realSize(), enc);
} else {
startp[0] = match.end(0) + 1;
startp[0] = matchEnd + 1;
}
} else {
startp[0] = match.end(0);
startp[0] = matchEnd;
}
if (match.numRegs() == 1) {
return RubyRegexp.nth_match(0, match);
@@ -5185,11 +5187,10 @@ public IRubyObject to_c(ThreadContext context) {

RubyArray a = RubyComplex.str_to_c_internal(context, s);

if (!a.eltInternal(0).isNil()) {
return a.eltInternal(0);
} else {
return RubyComplex.newComplexCanonicalize(context, RubyFixnum.zero(runtime));
}
IRubyObject first = a.eltInternal(0);
if ( ! first.isNil() ) return first;

return RubyComplex.newComplexCanonicalize(context, RubyFixnum.zero(runtime));
}

/** string_to_r
@@ -5205,11 +5206,10 @@ public IRubyObject to_r(ThreadContext context) {

RubyArray a = RubyRational.str_to_r_internal(context, s);

if (!a.eltInternal(0).isNil()) {
return a.eltInternal(0);
} else {
return RubyRational.newRationalCanonicalize(context, RubyFixnum.zero(runtime));
}
IRubyObject first = a.eltInternal(0);
if ( ! first.isNil() ) return first;

return RubyRational.newRationalCanonicalize(context, RubyFixnum.zero(runtime));
}

public static RubyString unmarshalFrom(UnmarshalStream input) throws java.io.IOException {
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ast/DNode.java
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ public DNode(ISourcePosition position) {
public DNode(ISourcePosition position, Encoding encoding) {
super(position);

assert encoding != null: "" + getClass().getName() + " passed in a null encoding";
assert encoding != null: getClass().getName() + " passed in a null encoding";

this.encoding = encoding;
}
Original file line number Diff line number Diff line change
@@ -29,6 +29,6 @@ public AnnotationExpression getExpression() {

@Override
public String toString() {
return "" + name + "=" + expression;
return name + '=' + expression;
}
}
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/compiler/JITCompiler.java
Original file line number Diff line number Diff line change
@@ -429,7 +429,8 @@ static void log(RubyModule implementationClass, String file, int line, String na

name = isBlock ? "" : "." + name;

StringBuilder builder = new StringBuilder(message + ":" + className + name + " at " + file + ":" + line);
StringBuilder builder = new StringBuilder(32);
builder.append(message).append(':').append(className).append(name).append(" at ").append(file).append(':').append(line);

if (reason.length > 0) {
builder.append(" because of: \"");
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/embed/ScriptingContainer.java
Original file line number Diff line number Diff line change
@@ -1696,7 +1696,7 @@ public void setReader(Reader reader) {
public Reader getReader() {
Map map = getAttributeMap();
if (map.containsKey(AttributeName.READER)) {
return (Reader) getAttributeMap().get(AttributeName.READER);
return (Reader) map.get(AttributeName.READER);
}
return null;
}
@@ -1761,7 +1761,7 @@ public void resetWriter() {
public Writer getWriter() {
Map map = getAttributeMap();
if (map.containsKey(AttributeName.WRITER)) {
return (Writer) getAttributeMap().get(AttributeName.WRITER);
return (Writer) map.get(AttributeName.WRITER);
}
return null;
}
@@ -1825,7 +1825,7 @@ public void resetErrorWriter() {
public Writer getErrorWriter() {
Map map = getAttributeMap();
if (map.containsKey(AttributeName.ERROR_WRITER)) {
return (Writer) getAttributeMap().get(AttributeName.ERROR_WRITER);
return (Writer) map.get(AttributeName.ERROR_WRITER);
}
return null;
}
18 changes: 10 additions & 8 deletions core/src/main/java/org/jruby/exceptions/RaiseException.java
Original file line number Diff line number Diff line change
@@ -96,37 +96,39 @@ public RaiseException(Ruby runtime, RubyClass excptnClass, String msg, boolean n
if (msg == null) {
msg = "No message available";
}
providedMessage = "(" + excptnClass.getName() + ") " + msg;
providedMessage = '(' + excptnClass.getName() + ") " + msg;
this.nativeException = nativeException;
if (DEBUG) {
Thread.dumpStack();
}
final ThreadContext context = runtime.getCurrentContext();
setException((RubyException) Helpers.invoke(
runtime.getCurrentContext(),
context,
excptnClass,
"new",
RubyString.newUnicodeString(excptnClass.getRuntime(), msg)),
RubyString.newUnicodeString(runtime, msg)),
nativeException);
preRaise(runtime.getCurrentContext());
preRaise(context);
}

public RaiseException(Ruby runtime, RubyClass excptnClass, String msg, IRubyObject backtrace, boolean nativeException) {
super(msg);
if (msg == null) {
msg = "No message available";
}
providedMessage = "(" + excptnClass.getName() + ") " + msg;
providedMessage = '(' + excptnClass.getName() + ") " + msg;
this.nativeException = nativeException;
if (DEBUG) {
Thread.dumpStack();
}
final ThreadContext context = runtime.getCurrentContext();
setException((RubyException) Helpers.invoke(
runtime.getCurrentContext(),
context,
excptnClass,
"new",
RubyString.newUnicodeString(excptnClass.getRuntime(), msg)),
RubyString.newUnicodeString(runtime, msg)),
nativeException);
preRaise(runtime.getCurrentContext(), backtrace);
preRaise(context, backtrace);
}

public RaiseException(RubyException exception, boolean isNativeException) {
Original file line number Diff line number Diff line change
@@ -1321,10 +1321,10 @@ public IRubyObject infinite_p(ThreadContext context) {
public IRubyObject inspect(ThreadContext context) {
StringBuilder val = new StringBuilder("#<BigDecimal:");

val.append(Integer.toHexString(System.identityHashCode(this))).append(",");
val.append("'").append(callMethod(context, "to_s")).append("'").append(",");
val.append(getSignificantDigits().length()).append("(");
val.append(((getAllDigits().length() / 4) + 1) * 4).append(")").append(">");
val.append( Integer.toHexString(System.identityHashCode(this)) ).append(',');
val.append('\'').append( callMethod(context, "to_s") ).append('\'').append(',');
val.append( getSignificantDigits().length() ).append('(');
val.append( ((getAllDigits().length() / 4) + 1) * 4 ).append(')').append('>');

return getRuntime().newString(val.toString());
}
13 changes: 6 additions & 7 deletions core/src/main/java/org/jruby/ext/ffi/CallbackInfo.java
Original file line number Diff line number Diff line change
@@ -64,13 +64,12 @@ public class CallbackInfo extends Type {
* @return The newly created ruby class
*/
public static RubyClass createCallbackInfoClass(Ruby runtime, RubyModule module) {
RubyClass result = module.defineClassUnder(CLASS_NAME,
module.getClass("Type"),
ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
final RubyClass Type = module.getClass("Type");
RubyClass result = module.defineClassUnder(CLASS_NAME, Type, ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
result.defineAnnotatedMethods(CallbackInfo.class);
result.defineAnnotatedConstants(CallbackInfo.class);

module.getClass("Type").setConstant("Function", result);
Type.setConstant("Function", result);
return result;
}

@@ -177,20 +176,20 @@ public final boolean isStdcall() {

@JRubyMethod(name = "to_s")
public final IRubyObject to_s(ThreadContext context) {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(64);
sb.append("#<FFI::CallbackInfo [ ");
for (int i = 0; i < parameterTypes.length; ++i) {
sb.append(parameterTypes[i].toString().toLowerCase());
if (i < (parameterTypes.length - 1)) {
sb.append(", ");
}
}
sb.append(" ], " + returnType.toString().toLowerCase() + ">");
sb.append(" ], ").append(returnType.toString().toLowerCase()).append('>');
return context.runtime.newString(sb.toString());
}
@Override
public final String toString() {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(64);
sb.append("CallbackInfo[parameters=[");
for (int i = 0; i < parameterTypes.length; ++i) {
sb.append(parameterTypes[i].toString().toLowerCase());
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ext/ffi/MappedType.java
Original file line number Diff line number Diff line change
@@ -29,8 +29,8 @@ public final class MappedType extends Type {
private final CachingCallSite fromNativeCallSite = new FunctionalCachingCallSite("from_native");

public static RubyClass createConverterTypeClass(Ruby runtime, RubyModule ffiModule) {
RubyClass convClass = ffiModule.getClass("Type").defineClassUnder("Mapped", ffiModule.getClass("Type"),
ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
final RubyClass Type = ffiModule.getClass("Type");
RubyClass convClass = Type.defineClassUnder("Mapped", Type, ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
convClass.defineAnnotatedMethods(MappedType.class);
convClass.defineAnnotatedConstants(MappedType.class);

6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ext/ffi/StructByValue.java
Original file line number Diff line number Diff line change
@@ -19,12 +19,12 @@ public final class StructByValue extends Type {
private final RubyClass structClass;

public static RubyClass createStructByValueClass(Ruby runtime, RubyModule ffiModule) {
RubyClass sbvClass = ffiModule.defineClassUnder("StructByValue", ffiModule.getClass("Type"),
ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
final RubyClass Type = ffiModule.getClass("Type");
RubyClass sbvClass = ffiModule.defineClassUnder("StructByValue", Type, ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
sbvClass.defineAnnotatedMethods(StructByValue.class);
sbvClass.defineAnnotatedConstants(StructByValue.class);

ffiModule.getClass("Type").setConstant("Struct", sbvClass);
Type.setConstant("Struct", sbvClass);

return sbvClass;
}
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/ext/ffi/StructLayout.java
Original file line number Diff line number Diff line change
@@ -964,10 +964,6 @@ public static class ArrayProxy extends RubyObject {
|| type.getComponentType() instanceof StructByValue);
}

private final long getOffset(IRubyObject index) {
return getOffset(Util.int32Value(index));
}

private final long getOffset(int index) {
if (index < 0 || (index >= arrayType.length() && arrayType.length() > 0)) {
throw getRuntime().newIndexError("index " + index + " out of bounds");
4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/ext/ffi/TypeResolver.java
Original file line number Diff line number Diff line change
@@ -62,10 +62,6 @@ private synchronized Type lookupAndCacheType(Ruby runtime, RubySymbol name, Ruby
return type;
}

private Type lookupType(Ruby runtime, IRubyObject name) {
return lookupType(runtime, name, null);
}

private Type lookupType(Ruby runtime, IRubyObject name, IRubyObject typeMap) {
IRubyObject type = ffi.typedefs.fastARef(name);
if (type instanceof Type) {
Original file line number Diff line number Diff line change
@@ -72,23 +72,22 @@ public static void create(Ruby runtime) {

@JRubyMethod(required = 1, visibility = Visibility.PRIVATE)
public static IRubyObject initialize(IRubyObject recv, IRubyObject io) {
final Ruby runtime = recv.getRuntime();
if (io instanceof RubyIO) {
RubyIO rubyIO = (RubyIO)io;
OpenFile of = rubyIO.getOpenFile();
if (of.selectChannel() != null) {
SelectableChannel selChannel = of.selectChannel();

((RubyObject)recv).extend(
new IRubyObject[]{((RubyModule)recv.getRuntime().getModule("Net").getConstant("BufferedIO")).getConstant("NativeImplementation")});
SelectableChannel sc = (SelectableChannel)(selChannel);
recv.dataWrapStruct(new NativeImpl(sc));
SelectableChannel selChannel = of.selectChannel();
if (selChannel != null) {
IRubyObject NativeImpl = ((RubyModule) runtime.getModule("Net").getConstant("BufferedIO")).getConstant("NativeImplementation");
((RubyObject) recv).extend(new IRubyObject[]{ NativeImpl });
recv.dataWrapStruct(new NativeImpl(selChannel));
}
}

recv.getInstanceVariables().setInstanceVariable("@io", io);
recv.getInstanceVariables().setInstanceVariable("@read_timeout", recv.getRuntime().newFixnum(60));
recv.getInstanceVariables().setInstanceVariable("@debug_output", recv.getRuntime().getNil());
recv.getInstanceVariables().setInstanceVariable("@rbuf", RubyString.newEmptyString(recv.getRuntime()));
recv.getInstanceVariables().setInstanceVariable("@read_timeout", runtime.newFixnum(60));
recv.getInstanceVariables().setInstanceVariable("@debug_output", runtime.getNil());
recv.getInstanceVariables().setInstanceVariable("@rbuf", RubyString.newEmptyString(runtime));

return recv;
}
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ext/ripper/RipperLexer.java
Original file line number Diff line number Diff line change
@@ -2943,7 +2943,7 @@ private char scanHexLiteral(ByteList buffer, int count, boolean strict, String e
buffer.append(h1);

hexValue <<= 4;
hexValue |= Integer.parseInt("" + (char) h1, 16) & 15;
hexValue |= Integer.parseInt(String.valueOf((char) h1), 16) & 15;
}

// No hex value after the 'x'.
@@ -2969,7 +2969,7 @@ private int scanHex(int count, boolean strict, String errorMessage) throws IOExc
}

hexValue <<= 4;
hexValue |= Integer.parseInt("" + (char) h1, 16) & 15;
hexValue |= Integer.parseInt(String.valueOf((char) h1), 16) & 15;
}

// No hex value after the 'x'.
@@ -2990,7 +2990,7 @@ private char scanOct(int count) throws IOException {
}

value <<= 3;
value |= Integer.parseInt("" + (char) c, 8);
value |= Integer.parseInt(String.valueOf((char) c), 8);
}

return value;
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ext/ripper/StringTerm.java
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ public int parseString(RipperLexer lexer, LexerSource src) throws IOException {
// FIXME: How much more obtuse can this be?
// Heredoc already parsed this and saved string...Do not parse..just return
if (flags == -1) {
lexer.setValue(new Token("" + end));
lexer.setValue(new Token(String.valueOf(end)));
lexer.ignoreNextScanEvent = true;
return Tokens.tSTRING_END;
}
@@ -144,7 +144,7 @@ public int parseString(RipperLexer lexer, LexerSource src) throws IOException {
}

private String parseRegexpFlags(RipperLexer lexer, LexerSource src) throws IOException {
StringBuilder buf = new StringBuilder(""+end);
StringBuilder buf = new StringBuilder(end);

int c;
StringBuilder unknownFlags = new StringBuilder(10);
14 changes: 8 additions & 6 deletions core/src/main/java/org/jruby/ext/socket/Ifaddr.java
Original file line number Diff line number Diff line change
@@ -206,17 +206,19 @@ private void setInspectString(NetworkInterface nif) throws SocketException {

private String ipAddress() {
if (address instanceof Inet4Address) {
return address.toString().substring(1, address.toString().length());
final String addr = address.toString();
return addr.substring(1, addr.length());
} else if ((address instanceof Inet6Address)) {
return address.toString().substring(1, address.toString().length()).split("%")[0];
final String addr = address.toString();
return addr.substring(1, addr.length()).split("%")[0];
}
return "";
}

private String getBroadcastAsString() {
if (broadcast == null) {
return "";
}
return broadcast.toString().substring(1, broadcast.toString().length());
if (broadcast == null) return "";
final String brdc = broadcast.toString();
return brdc.substring(1, brdc.length());
}

}
10 changes: 4 additions & 6 deletions core/src/main/java/org/jruby/ext/socket/RubySocket.java
Original file line number Diff line number Diff line change
@@ -266,15 +266,13 @@ public static IRubyObject getifaddrs(ThreadContext context, IRubyObject recv) {
RubyArray list = RubyArray.newArray(context.runtime);
try {
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
RubyClass Ifaddr = (RubyClass) context.runtime.getClassFromPath("Socket::Ifaddr");
while (en.hasMoreElements()) {
NetworkInterface ni = en.nextElement();
// create interface link layer ifaddr
list.append(new Ifaddr(context.runtime, (RubyClass)context.runtime.getClassFromPath("Socket::Ifaddr"), ni));
List<InterfaceAddress> listIa = ni.getInterfaceAddresses();
Iterator<InterfaceAddress> it = listIa.iterator();
while (it.hasNext()) {
InterfaceAddress ia = it.next();
list.append(new Ifaddr(context.runtime, (RubyClass)context.runtime.getClassFromPath("Socket::Ifaddr"), ni, ia));
list.append(new Ifaddr(context.runtime, Ifaddr, ni));
for ( InterfaceAddress ia : ni.getInterfaceAddresses() ) {
list.append(new Ifaddr(context.runtime, Ifaddr, ni, ia));
}
}
} catch (Exception ex) {
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ext/socket/RubyUDPSocket.java
Original file line number Diff line number Diff line change
@@ -283,7 +283,7 @@ public IRubyObject send(ThreadContext context, IRubyObject[] args) {
ByteBuffer buf = ByteBuffer.wrap(data.getBytes());

byte[] buf2 = data.getBytes();
DatagramPacket sendDP = null;
DatagramPacket sendDP;

int port;
if (_port instanceof RubyString) {
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/ext/socket/RubyUNIXSocket.java
Original file line number Diff line number Diff line change
@@ -147,7 +147,7 @@ public IRubyObject recv_io(IRubyObject[] args) {

@JRubyMethod(name = {"socketpair", "pair"}, optional = 2, meta = true)
public static IRubyObject socketpair(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Ruby runtime = context.runtime;
final Ruby runtime = context.runtime;

// TODO: type and protocol

@@ -156,17 +156,17 @@ public static IRubyObject socketpair(ThreadContext context, IRubyObject recv, IR
try {
sp = UnixSocketChannel.pair();

RubyUNIXSocket sock = (RubyUNIXSocket)(Helpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));
final RubyClass UNIXSocket = runtime.getClass("UNIXSocket");
RubyUNIXSocket sock = (RubyUNIXSocket)(Helpers.invoke(context, UNIXSocket, "allocate"));
sock.init_sock(runtime, sp[0], "");

RubyUNIXSocket sock2 = (RubyUNIXSocket)(Helpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));
RubyUNIXSocket sock2 = (RubyUNIXSocket)(Helpers.invoke(context, UNIXSocket, "allocate"));
sock2.init_sock(runtime, sp[1], "");

return runtime.newArray(sock, sock2);

} catch (IOException ioe) {
throw runtime.newIOErrorFromException(ioe);

}
}

9 changes: 2 additions & 7 deletions core/src/main/java/org/jruby/ext/socket/SocketUtils.java
Original file line number Diff line number Diff line change
@@ -529,7 +529,7 @@ public static RuntimeException sockerr_with_trace(Ruby runtime, String msg, Stac
StringBuilder sb = new StringBuilder();
sb.append(msg);
for (int i = 0, il = trace.length; i < il; i++) {
sb.append(eol + trace[i].toString());
sb.append(eol).append(trace[i].toString());
}
return new RaiseException(runtime, runtime.getClass("SocketError"), sb.toString(), true);
}
@@ -565,12 +565,7 @@ private static String getHostAddress(ThreadContext context, InetAddress addr, Bo
return ret;
}

private static String getHostAddress(ThreadContext context, InetAddress addr) {
return getHostAddress(context, addr, null);
}

private static final Pattern STRING_IPV4_ADDRESS_PATTERN =
Pattern.compile("((.*)\\/)?([\\.0-9]+)(:([0-9]+))?");
private static final Pattern STRING_IPV4_ADDRESS_PATTERN = Pattern.compile("((.*)\\/)?([\\.0-9]+)(:([0-9]+))?");

private static final int IPV4_HOST_GROUP = 3;
private static final int IPV4_PORT_GROUP = 5;
15 changes: 6 additions & 9 deletions core/src/main/java/org/jruby/ext/socket/SubnetUtils.java
Original file line number Diff line number Diff line change
@@ -189,15 +189,12 @@ public String[] getAllAddresses() {
*/
@Override
public String toString() {
final StringBuilder buf = new StringBuilder();
buf.append("CIDR Signature:\t[").append(getCidrSignature()).append("]")
.append(" Netmask: [").append(getNetmask()).append("]\n")
.append("Network:\t[").append(getNetworkAddress()).append("]\n")
.append("Broadcast:\t[").append(getBroadcastAddress()).append("]\n")
.append("First Address:\t[").append(getLowAddress()).append("]\n")
.append("Last Address:\t[").append(getHighAddress()).append("]\n")
.append("# Addresses:\t[").append(getAddressCount()).append("]\n");
return buf.toString();
return "CIDR Signature:\t[" + getCidrSignature() + "] Netmask: [" + getNetmask() + "]\n" +
"Network:\t[" + getNetworkAddress() + "]\n" +
"Broadcast:\t[" + getBroadcastAddress() + "]\n" +
"First Address:\t[" + getLowAddress() + "]\n" +
"Last Address:\t[" + getHighAddress() + "]\n" +
"# Addresses:\t[" + getAddressCount() + "]\n" ;
}
}

4 changes: 0 additions & 4 deletions core/src/main/java/org/jruby/ext/stringio/StringIO.java
Original file line number Diff line number Diff line change
@@ -790,10 +790,6 @@ private RubyString makeString(Ruby runtime, ByteList buf, boolean setEncoding) {

return str;
}

private RubyString makeString(Ruby runtime, ByteList buf) {
return makeString(runtime, buf, true);
}

@JRubyMethod(name = "read", optional = 2)
public IRubyObject read(ThreadContext context, IRubyObject[] args) {
Original file line number Diff line number Diff line change
@@ -501,7 +501,7 @@ public IRubyObject getc_19() {
position++;
// TODO: must handle encoding. Move encoding handling methods to util class from RubyIO and use it.
// TODO: StringIO needs a love, too.
return getRuntime().newString("" + (char) (value & 0xFF));
return getRuntime().newString(String.valueOf((char) (value & 0xFF)));
} catch (IOException ioe) {
throw getRuntime().newIOErrorFromException(ioe);
}
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ public Thread getThread() {
}

public String toString() {
return "" + getThread();
return String.valueOf(getThread());
}

public Thread nativeThread() {
Original file line number Diff line number Diff line change
@@ -446,7 +446,7 @@ public Method getMethod() {

@Override
public String toString() {
return "" + (statik?"static ":"") + nativeReturn.getSimpleName() + " " + nativeTarget.getSimpleName() + "." + nativeName + CodegenUtils.prettyShortParams(nativeSignature);
return (statik ? "static " :"") + nativeReturn.getSimpleName() + ' ' + nativeTarget.getSimpleName() + '.' + nativeName + CodegenUtils.prettyShortParams(nativeSignature);
}
}

2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/IRScope.java
Original file line number Diff line number Diff line change
@@ -511,7 +511,7 @@ private void runCompilerPasses(List<CompilerPass> passes) {
public InterpreterContext allocateInterpreterContext(List<Instr> instructions) {
interpreterContext = new InterpreterContext(this, instructions);

if (RubyInstanceConfig.IR_COMPILER_DEBUG) LOG.info("" + interpreterContext);
if (RubyInstanceConfig.IR_COMPILER_DEBUG) LOG.info(interpreterContext.toString());

return interpreterContext;
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/instructions/GetInstr.java
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ public abstract class GetInstr extends OneOperandResultBaseInstr implements Fixe
public GetInstr(Operation op, Variable result, Operand source, String ref) {
super(op, result, source);

assert result != null: "" + getClass().getSimpleName() + " result is null";
assert result != null: getClass().getSimpleName() + " result is null";

this.ref = ref;
}
Original file line number Diff line number Diff line change
@@ -50,9 +50,9 @@ public void endExecute(CompilerPass pass, IRScope scope, Object data, boolean ch

private String getScopeUUID(IRScope scope) {
if (scope instanceof IRScriptBody || scope instanceof IRClosure) {
return "" + scope.getFileName() + "#" + scope.getLineNumber() + "#";
return scope.getFileName() + '#' + scope.getLineNumber() + '#';
}

return "" + scope.getFileName() + "#" + scope.getLineNumber() + "#" + scope.getName();
return scope.getFileName() + '#' + scope.getLineNumber() + '#' + scope.getName();
}
}
Original file line number Diff line number Diff line change
@@ -198,7 +198,7 @@ public String toString() {
}

public String toStringInstrs() {
StringBuilder buf = new StringBuilder(toString() + "\n");
StringBuilder buf = new StringBuilder(toString()).append("\n");

for (Instr instr : getInstrs()) {
buf.append('\t').append(instr).append('\n');
Original file line number Diff line number Diff line change
@@ -123,12 +123,14 @@ public static Class defineOldStyleImplClass(Ruby ruby, String name, String[] sup

int cacheSize = 0;

final HashSet<String> implementedNames = new HashSet<String>();

// for each simple method name, implement the complex methods, calling the simple version
for (Map.Entry<String, List<Method>> entry : simpleToAll.entrySet()) {
String simpleName = entry.getKey();
Set<String> nameSet = JavaUtil.getRubyNamesForJavaName(simpleName, entry.getValue());

Set<String> implementedNames = new HashSet<String>();
implementedNames.clear();

for (Method method : entry.getValue()) {
Class[] paramTypes = method.getParameterTypes();
@@ -345,13 +347,15 @@ public static Class defineRealImplClass(Ruby ruby, String name, Class superClass
}

int cacheSize = 0;


final HashSet<String> implementedNames = new HashSet<String>();

// for each simple method name, implement the complex methods, calling the simple version
for (Map.Entry<String, List<Method>> entry : simpleToAll.entrySet()) {
String simpleName = entry.getKey();
Set<String> nameSet = JavaUtil.getRubyNamesForJavaName(simpleName, entry.getValue());

Set<String> implementedNames = new HashSet<String>();
implementedNames.clear();

for (Method method : entry.getValue()) {
Class[] paramTypes = method.getParameterTypes();
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public JavaInternalBlockBody(Ruby runtime, ThreadContext originalContext, String
// Make sure we are still on the same thread as originator if we care
private void threadCheck(ThreadContext yieldingContext) {
if (originalContext != null && yieldingContext != originalContext) {
throw yieldingContext.runtime.newThreadError("" + methodName + " cannot be parallelized");
throw yieldingContext.runtime.newThreadError(methodName + " cannot be parallelized");
}
}

Original file line number Diff line number Diff line change
@@ -145,10 +145,6 @@ private String quote(int num) {
return String.format("\"%d\"", num);
}

private String quote(long num) {
return String.format("\"%d\"", num);
}

private String toJsonArray(String... values) {
StringBuffer buffer = new StringBuffer();
buffer.append("[");
8 changes: 3 additions & 5 deletions core/src/main/java/org/jruby/util/Pack.java
Original file line number Diff line number Diff line change
@@ -510,11 +510,9 @@ private static ByteList encodes(Ruby runtime, ByteList io2Append,byte[]charsToEn
byte lPadding;
if (encodingType == 'u') {
if (charCount >= lTranslationTable.length) {
throw runtime.newArgumentError(
""
+ charCount
+ " is not a correct value for the number of bytes per line in a u directive. Correct values range from 0 to "
+ lTranslationTable.length);
throw runtime.newArgumentError(charCount
+ " is not a correct value for the number of bytes per line in a u directive. Correct values range from 0 to "
+ lTranslationTable.length);
}
io2Append.append(lTranslationTable[charCount]);
lPadding = '`';
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ private void processArgument() {
} else {
try {
int val = Integer.parseInt(temp, 8);
config.setRecordSeparator("" + (char) val);
config.setRecordSeparator(String.valueOf((char) val));
} catch (Exception e) {
MainExitException mee = new MainExitException(1, getArgumentError(" -0 must be followed by either 0, 777, or a valid octal value"));
mee.setUsageError(true);
48 changes: 23 additions & 25 deletions core/src/main/java/org/jruby/util/io/EncodingUtils.java
Original file line number Diff line number Diff line change
@@ -1232,11 +1232,10 @@ public static void transcodeLoop(ThreadContext context, byte[] inBytes, Ptr inPo

// make_econv_exception
public static RaiseException makeEconvException(Ruby runtime, EConv ec) {
String mesg;
RaiseException exc;
final StringBuilder mesg = new StringBuilder(); RaiseException exc;

if (ec.lastError.getResult() == EConvResult.InvalidByteSequence ||
ec.lastError.getResult() == EConvResult.IncompleteInput) {
final EConvResult result = ec.lastError.getResult();
if (result == EConvResult.InvalidByteSequence || result == EConvResult.IncompleteInput) {
byte[] errBytes = ec.lastError.getErrorBytes();
int errBytesP = ec.lastError.getErrorBytesP();
int errorLen = ec.lastError.getErrorBytesLength();
@@ -1245,48 +1244,47 @@ public static RaiseException makeEconvException(Ruby runtime, EConv ec) {
RubyString dumped = (RubyString)bytes.dump();
int readagainLen = ec.lastError.getReadAgainLength();
IRubyObject bytes2 = runtime.getNil();
IRubyObject dumped2;
int idx;
if (ec.lastError.getResult() == EConvResult.IncompleteInput) {
mesg = "incomplete " + dumped + " on " + new String(ec.lastError.getSource());
if (result == EConvResult.IncompleteInput) {
mesg.append("incomplete ").append(dumped).append(" on ").append(new String(ec.lastError.getSource()));
} else if (readagainLen != 0) {
bytes2 = RubyString.newString(runtime, new ByteList(errBytes, errorLen + errBytesP, ec.lastError.getReadAgainLength()));
dumped2 = ((RubyString)bytes2).dump();
mesg = dumped + " followed by " + dumped2 + " on " + new String(ec.lastError.getSource());
IRubyObject dumped2 = ((RubyString) bytes2).dump();
mesg.append(dumped).append(" followed by ").append(dumped2).append(" on ").append( new String(ec.lastError.getSource()) );
} else {
mesg = dumped + " on " + new String(ec.lastError.getSource());
mesg.append(dumped).append(" on ").append( new String(ec.lastError.getSource()) );
}

exc = runtime.newInvalidByteSequenceError(mesg);
exc = runtime.newInvalidByteSequenceError(mesg.toString());
exc.getException().setInternalVariable("error_bytes", bytes);
exc.getException().setInternalVariable("readagain_bytes", bytes2);
exc.getException().setInternalVariable("incomplete_input", ec.lastError.getResult() == EConvResult.IncompleteInput ? runtime.getTrue() : runtime.getFalse());
exc.getException().setInternalVariable("incomplete_input", result == EConvResult.IncompleteInput ? runtime.getTrue() : runtime.getFalse());

return makeEConvExceptionSetEncs(exc, runtime, ec);
} else if (ec.lastError.getResult() == EConvResult.UndefinedConversion) {
}
else if (result == EConvResult.UndefinedConversion) {
byte[] errBytes = ec.lastError.getErrorBytes();
int errBytesP = ec.lastError.getErrorBytesP();
int errorLen = ec.lastError.getErrorBytesLength();
ByteList _bytes = new ByteList(errBytes, errBytesP, errorLen - errBytesP);
RubyString bytes = RubyString.newString(runtime, _bytes);
if (Arrays.equals(ec.lastError.getSource(), "UTF-8".getBytes())) {
final byte[] errSource = ec.lastError.getSource();
if (Arrays.equals(errSource, "UTF-8".getBytes())) {
// prepare dumped form
}
RubyString dumped = (RubyString)bytes.dump();

if (Arrays.equals(ec.lastError.getSource(), ec.source) &&
Arrays.equals(ec.lastError.getDestination(), ec.destination)) {
mesg = dumped + " from " + new String(ec.lastError.getSource()) + " to " + new String(ec.lastError.getDestination());
RubyString bytes = RubyString.newString(runtime, new ByteList(errBytes, errBytesP, errorLen - errBytesP));
RubyString dumped = (RubyString) bytes.dump();

if (Arrays.equals(errSource, ec.source) && Arrays.equals(ec.lastError.getDestination(), ec.destination)) {
mesg.append(dumped).append(" from ").append( new String(errSource) ).append(" to ").append( new String(ec.lastError.getDestination()) );
} else {
mesg = dumped + " to " + new String(ec.lastError.getDestination()) + " in conversion from " + new String(ec.source);
mesg.append(dumped).append(" to ").append( new String(ec.lastError.getDestination()) ).append(" in conversion from ").append( new String(ec.source) );
for (int i = 0; i < ec.numTranscoders; i++) {
mesg += " to " + new String(ec.elements[i].transcoding.transcoder.getDestination());
mesg.append(" to ").append( new String(ec.elements[i].transcoding.transcoder.getDestination()) );
}
}

exc = runtime.newUndefinedConversionError(mesg);
exc = runtime.newUndefinedConversionError(mesg.toString());

EncodingDB.Entry entry = runtime.getEncodingService().findEncodingOrAliasEntry(ec.lastError.getSource());
EncodingDB.Entry entry = runtime.getEncodingService().findEncodingOrAliasEntry(errSource);
if (entry != null) {
bytes.setEncoding(entry.getEncoding());
exc.getException().setInternalVariable("error_char", bytes);
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/util/io/ModeFlags.java
Original file line number Diff line number Diff line change
@@ -340,7 +340,8 @@ public boolean isSubsetOf(ModeFlags superset) {

@Override
public String toString() {
StringBuilder buf = new StringBuilder("ModeFlags(" + flags + "): ");
StringBuilder buf = new StringBuilder();
buf.append("ModeFlags(").append(flags).append("): ");

if (isAppendable()) buf.append("APPENDABLE ");
if (isBinary()) buf.append("BINARY ");

0 comments on commit 976c968

Please sign in to comment.