Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -4164,6 +4164,7 @@ public RaiseException newFrozenError(String objectType, IRubyObject receiver) {
return newFrozenError(receiver, message);
}

@Deprecated(since = "10.0")
public RaiseException newFrozenError(IRubyObject receiver, String message) {
ThreadContext context = getCurrentContext();

Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@
import static org.jruby.RubyEnumerator.enumeratorizeWithSize;
import static org.jruby.RubyEnumerator.enumWithSize;
import static org.jruby.api.Convert.*;
import static org.jruby.api.Error.argumentError;
import static org.jruby.api.Error.typeError;
import static org.jruby.api.Error.*;
import static org.jruby.runtime.Helpers.*;
import static org.jruby.runtime.Visibility.PRIVATE;
import static org.jruby.util.Inspector.*;
Expand Down Expand Up @@ -4715,7 +4714,7 @@ private IRubyObject shuffleBang(ThreadContext context, IRubyObject randgen) {
while (i > 0) {
int r = (int) RubyRandom.randomLongLimited(context, randgen, i - 1);
if (len != realLength) { // || ptr != RARRAY_CONST_PTR(ary)
throw context.runtime.newRuntimeError("modified during shuffle");
throw runtimeError(context, "modified during shuffle");
}
T tmp = eltOk(--i);
eltSetOk(i, eltOk(r));
Expand Down
30 changes: 13 additions & 17 deletions core/src/main/java/org/jruby/RubyConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
import java.util.HashMap;
import java.util.Map;

import static org.jcodings.transcode.EConvResult.*;
import static org.jruby.api.Convert.*;
import static org.jruby.api.Create.newArray;
import static org.jruby.api.Create.newString;
import static org.jruby.api.Error.argumentError;
import static org.jruby.api.Error.typeError;
import static org.jruby.api.Error.*;
import static org.jruby.runtime.Visibility.PRIVATE;

@JRubyClass(name="Converter")
Expand Down Expand Up @@ -357,22 +357,18 @@ public IRubyObject convert(ThreadContext context, IRubyObject srcBuffer) {

IRubyObject ret = primitive_convert(context, newArgs);

if (ret instanceof RubySymbol) {
RubySymbol retSym = (RubySymbol)ret;
if (ret instanceof RubySymbol retSym) {
String retStr = retSym.asJavaString(); // 7bit comparison

if (retStr.equals(EConvResult.InvalidByteSequence.symbolicName()) ||
retStr.equals(EConvResult.UndefinedConversion.symbolicName()) ||
retStr.equals(EConvResult.IncompleteInput.symbolicName())) {
if (retStr.equals(InvalidByteSequence.symbolicName()) ||
retStr.equals(UndefinedConversion.symbolicName()) ||
retStr.equals(IncompleteInput.symbolicName())) {
throw EncodingUtils.makeEconvException(context.runtime, ec);
}

if (retStr.equals(EConvResult.Finished.symbolicName())) {
throw argumentError(context, "converter already finished");
}

if (!retStr.equals(EConvResult.SourceBufferEmpty.symbolicName())) {
throw context.runtime.newRuntimeError("bug: unexpected result of primitive_convert: " + retSym);
if (retStr.equals(Finished.symbolicName())) throw argumentError(context, "converter already finished");
if (!retStr.equals(SourceBufferEmpty.symbolicName())) {
throw runtimeError(context, "bug: unexpected result of primitive_convert: " + retSym);
}
}

Expand All @@ -397,14 +393,14 @@ public IRubyObject finish(ThreadContext context) {
RubySymbol retSym = (RubySymbol)ret;
String retStr = retSym.asJavaString(); // 7 bit comparison

if (retStr.equals(EConvResult.InvalidByteSequence.symbolicName()) ||
retStr.equals(EConvResult.UndefinedConversion.symbolicName()) ||
retStr.equals(EConvResult.IncompleteInput.symbolicName())) {
if (retStr.equals(InvalidByteSequence.symbolicName()) ||
retStr.equals(UndefinedConversion.symbolicName()) ||
retStr.equals(IncompleteInput.symbolicName())) {
throw EncodingUtils.makeEconvException(context.runtime, ec);
}

if (!retStr.equals(EConvResult.Finished.symbolicName())) {
throw context.runtime.newRuntimeError("bug: unexpected result of primitive_convert");
throw runtimeError(context, "bug: unexpected result of primitive_convert");
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import static org.jruby.api.Create.newArray;
import static org.jruby.api.Create.newString;
import static org.jruby.api.Error.argumentError;
import static org.jruby.api.Error.runtimeError;
import static org.jruby.util.RubyStringBuilder.str;
import static org.jruby.util.io.EncodingUtils.newExternalStringWithEncoding;

Expand Down Expand Up @@ -462,7 +463,7 @@ private static IRubyObject chdirCommon(ThreadContext context, Block block, RubyS
adjustedPath = getExistingDir(runtime, adjustedPath).canonicalPath();

if (runtime.getChdirThread() != null && context.getThread() != runtime.getChdirThread()) {
throw runtime.newRuntimeError("conflicting chdir during another chdir block");
throw runtimeError(context, "conflicting chdir during another chdir block");
}

if(!block.isGiven() && runtime.getChdirThread() != null) {
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
import static org.jruby.api.Convert.asFixnum;
import static org.jruby.api.Convert.numericToLong;
import static org.jruby.api.Create.*;
import static org.jruby.api.Error.argumentError;
import static org.jruby.api.Error.typeError;
import static org.jruby.api.Error.*;
import static org.jruby.runtime.Helpers.arrayOf;
import static org.jruby.runtime.Helpers.invokedynamic;
import static org.jruby.runtime.builtin.IRubyObject.NULL_ARRAY;
Expand Down Expand Up @@ -2192,7 +2191,7 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block)
arg.prev_value = arg.prev_elts = ctx.nil;
}
} else if ( (v instanceof RubySymbol) && v.toString().charAt(0) == '_' ) {
throw runtime.newRuntimeError("symbol begins with an underscore is reserved");
throw runtimeError(context, "symbol begins with an underscore is reserved");
} else {
if ( arg.prev_value.isNil() ) {
arg.prev_value = v;
Expand Down
10 changes: 4 additions & 6 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import static org.jruby.api.Convert.*;
import static org.jruby.api.Create.*;
import static org.jruby.api.Error.argumentError;
import static org.jruby.api.Error.runtimeError;
import static org.jruby.runtime.ThreadContext.hasKeywords;
import static org.jruby.runtime.Visibility.PRIVATE;
import static org.jruby.util.StringSupport.*;
Expand Down Expand Up @@ -354,16 +355,13 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block b
int maxArgs = keywords ? 4 : 3;
int argc = Arity.checkArgumentCount(context, args, 1, maxArgs);

if (openFile != null) throw context.runtime.newRuntimeError("reinitializing File");
if (openFile != null) throw runtimeError(context, "reinitializing File");

if (argc > 0 && argc <= 3) {
IRubyObject fd = TypeConverter.convertToTypeWithCheck(context, args[0], context.runtime.getFixnum(), sites(context).to_int_checked);
if (!fd.isNil()) {
if (argc == 1) {
return super.initialize(context, fd, block);
} else if (argc == 2) {
return super.initialize(context, fd, args[1], block);
}
if (argc == 1) return super.initialize(context, fd, block);
if (argc == 2) return super.initialize(context, fd, args[1], block);
return super.initialize(context, fd, args[1], args[2], block);
}
}
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@
import static org.jruby.api.Convert.asBoolean;
import static org.jruby.api.Convert.asFixnum;
import static org.jruby.api.Create.newArray;
import static org.jruby.api.Error.argumentError;
import static org.jruby.api.Error.typeError;
import static org.jruby.api.Error.*;
import static org.jruby.runtime.Visibility.PRIVATE;
import static org.jruby.util.Inspector.*;

Expand Down Expand Up @@ -1026,9 +1025,7 @@ public IRubyObject to_s(ThreadContext context) {
*/
@JRubyMethod(name = "rehash")
public RubyHash rehash(ThreadContext context) {
if (iteratorCount > 0) {
throw context.runtime.newRuntimeError("rehash during iteration");
}
if (iteratorCount > 0) throw runtimeError(context, "rehash during iteration");

modify();
final RubyHashEntry[] oldTable = table;
Expand Down
17 changes: 5 additions & 12 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@
import static org.jruby.anno.FrameField.LASTLINE;
import static org.jruby.api.Convert.*;
import static org.jruby.api.Create.*;
import static org.jruby.api.Error.argumentError;
import static org.jruby.api.Error.typeError;
import static org.jruby.api.Error.*;
import static org.jruby.runtime.ThreadContext.*;
import static org.jruby.runtime.Visibility.*;
import static org.jruby.util.RubyStringBuilder.str;
Expand Down Expand Up @@ -157,9 +156,7 @@ public RubyIO(Ruby runtime, OutputStream outputStream, boolean autoclose) {
super(runtime, runtime.getIO());

// We only want IO objects with valid streams (better to error now).
if (outputStream == null) {
throw runtime.newRuntimeError("Opening null stream");
}
if (outputStream == null) throw runtime.newRuntimeError("Opening null stream");

openFile = MakeOpenFile();
openFile.setFD(new ChannelFD(writableChannel(outputStream), runtime.getPosix(), runtime.getFilenoUtil()));
Expand All @@ -170,9 +167,7 @@ public RubyIO(Ruby runtime, OutputStream outputStream, boolean autoclose) {
public RubyIO(Ruby runtime, InputStream inputStream) {
super(runtime, runtime.getIO());

if (inputStream == null) {
throw runtime.newRuntimeError("Opening null stream");
}
if (inputStream == null) throw runtime.newRuntimeError("Opening null stream");

openFile = MakeOpenFile();
openFile.setFD(new ChannelFD(readableChannel(inputStream), runtime.getPosix(), runtime.getFilenoUtil()));
Expand All @@ -185,13 +180,11 @@ public RubyIO(Ruby runtime, Channel channel) {

public RubyIO(Ruby runtime, RubyClass klass, Channel channel) {
super(runtime, klass);
var context = runtime.getCurrentContext();

// We only want IO objects with valid streams (better to error now).
if (channel == null) {
throw runtime.newRuntimeError("Opening null channel");
}
if (channel == null) throw runtimeError(context, "Opening null channel");

ThreadContext context = runtime.getCurrentContext();
var posix = runtime.getPosix();
initializeCommon(context, new ChannelFD(channel, posix, runtime.getFilenoUtil()),
asFixnum(context, ModeFlags.oflagsFrom(posix, channel)), context.nil);
Expand Down
9 changes: 4 additions & 5 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@
import static org.jruby.anno.FrameField.VISIBILITY;
import static org.jruby.api.Convert.*;
import static org.jruby.api.Create.*;
import static org.jruby.api.Error.argumentError;
import static org.jruby.api.Error.typeError;
import static org.jruby.api.Error.*;
import static org.jruby.runtime.Visibility.MODULE_FUNCTION;
import static org.jruby.runtime.Visibility.PRIVATE;
import static org.jruby.runtime.Visibility.PROTECTED;
Expand Down Expand Up @@ -878,7 +877,7 @@ private String calculateAnonymousName() {
@JRubyMethod(required = 1)
public IRubyObject set_temporary_name(ThreadContext context, IRubyObject arg) {
if (baseName != null && IdUtil.isValidConstantName(baseName) && (parent == null || parent.baseName != null)) {
throw context.runtime.newRuntimeError("can't change permanent name");
throw runtimeError(context, "can't change permanent name");
}

if (arg.isNil()) {
Expand Down Expand Up @@ -1016,9 +1015,9 @@ private void addActivatedRefinement(ThreadContext context, RubyModule moduleToRe

@JRubyMethod(name = "using", visibility = PRIVATE, reads = {SELF, SCOPE})
public IRubyObject using(ThreadContext context, IRubyObject refinedModule) {
if (context.getFrameSelf() != this) throw context.runtime.newRuntimeError("Module#using is not called on self");
if (context.getFrameSelf() != this) throw runtimeError(context, "Module#using is not called on self");
if (context.getCurrentStaticScope().isWithinMethod()) {
throw context.runtime.newRuntimeError("Module#using is not permitted in methods");
throw runtimeError(context, "Module#using is not permitted in methods");
}

// I pass the cref even though I don't need to so that the concept is simpler to read
Expand Down
7 changes: 3 additions & 4 deletions core/src/main/java/org/jruby/RubyObjectSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
import static org.jruby.api.Convert.*;
import static org.jruby.api.Create.newArray;
import static org.jruby.api.Create.newArrayNoCopy;
import static org.jruby.api.Error.argumentError;
import static org.jruby.api.Error.typeError;
import static org.jruby.api.Error.*;
import static org.jruby.runtime.Visibility.*;
import static org.jruby.util.Inspector.inspectPrefix;

Expand Down Expand Up @@ -210,8 +209,8 @@ public static IRubyObject each_objectInternal(final ThreadContext context, IRuby
}
return asFixnum(context, count);
}
if ( ! runtime.isObjectSpaceEnabled() ) {
throw runtime.newRuntimeError("ObjectSpace is disabled; each_object will only work with Class, pass -X+O to enable");
if (!runtime.isObjectSpaceEnabled()) {
throw runtimeError(context, "ObjectSpace is disabled; each_object will only work with Class, pass -X+O to enable");
}
final Iterator iter = runtime.getObjectSpace().iterator(rubyClass);
IRubyObject obj; int count = 0;
Expand Down
48 changes: 14 additions & 34 deletions core/src/main/java/org/jruby/RubyRational.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
import static org.jruby.api.Convert.*;
import static org.jruby.api.Create.newArray;
import static org.jruby.api.Create.newString;
import static org.jruby.api.Error.argumentError;
import static org.jruby.api.Error.typeError;
import static org.jruby.api.Error.*;
import static org.jruby.ast.util.ArgsUtil.hasExceptionOption;
import static org.jruby.runtime.Helpers.invokedynamic;
import static org.jruby.runtime.invokedynamic.MethodNames.HASH;
Expand Down Expand Up @@ -1171,43 +1170,30 @@ public IRubyObject roundCommon(ThreadContext context, final IRubyObject n, Round
}

private IRubyObject doRound(ThreadContext context, RoundingMode mode) {
switch (mode) {
case HALF_UP:
return roundHalfUp(context);
case HALF_EVEN:
return roundHalfEven(context);
case HALF_DOWN:
return roundHalfDown(context);
case FLOOR:
return mriFloor(context);
case CEILING:
return mriCeil(context);
case UNNECESSARY:
return mriTruncate(context);
default:
throw context.runtime.newRuntimeError("BUG: invalid rounding mode: " + mode);
}
return switch (mode) {
case HALF_UP -> roundHalfUp(context);
case HALF_EVEN -> roundHalfEven(context);
case HALF_DOWN -> roundHalfDown(context);
case FLOOR -> mriFloor(context);
case CEILING -> mriCeil(context);
case UNNECESSARY -> mriTruncate(context);
default -> throw runtimeError(context, "BUG: invalid rounding mode: " + mode);
};
}

// MRI: nurat_round_half_down
private RubyInteger roundHalfDown(ThreadContext context) {

RubyInteger num = this.num, den = this.den;

final boolean neg = num.isNegative();

if (neg) {
num = (RubyInteger) num.op_uminus(context);
}
if (neg) num = (RubyInteger) num.op_uminus(context);

num = (RubyInteger) ((RubyInteger) num.op_mul(context, 2)).op_plus(context, den);
num = (RubyInteger) num.op_minus(context, 1);
den = (RubyInteger) den.op_mul(context, 2);
num = (RubyInteger) num.idiv(context, den);

if (neg) {
num = (RubyInteger) num.op_uminus(context);
}
if (neg) num = (RubyInteger) num.op_uminus(context);

return num;
}
Expand All @@ -1233,22 +1219,17 @@ private RubyInteger roundHalfEven(ThreadContext context) {

// MRI: nurat_round_half_up
private RubyInteger roundHalfUp(ThreadContext context) {

RubyInteger num = this.num, den = this.den;

final boolean neg = num.isNegative();

if (neg) {
num = (RubyInteger) num.op_uminus(context);
}
if (neg) num = (RubyInteger) num.op_uminus(context);

num = (RubyInteger) ((RubyInteger) num.op_mul(context, 2)).op_plus(context, den);
den = (RubyInteger) den.op_mul(context, 2);
num = (RubyInteger) num.idiv(context, den);

if (neg) {
num = (RubyInteger) num.op_uminus(context);
}
if (neg) num = (RubyInteger) num.op_uminus(context);

return num;
}
Expand All @@ -1270,7 +1251,6 @@ public double getDoubleValue() {
private static final long ML = (long)(Math.log(Double.MAX_VALUE) / Math.log(2.0) - 1);

public double getDoubleValue(ThreadContext context) {

if (f_zero_p(context, num)) return 0;

RubyInteger myNum = this.num;
Expand Down
Loading