Skip to content

Commit d2b9b15

Browse files
authored
Refactor: drop java.util.Collection#inspect extension (#14208)
since JRuby 9.3 a useful inspect is provided out of the box LS' inspect: <Java::JavaUtil::ArrayList:3536147 ["some"]> JRuby 9.3's: "#<Java::JavaUtil::ArrayList: [\"some\"]>"
1 parent 433b341 commit d2b9b15

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

logstash-core/spec/logstash/java_integration_spec.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
context "Java::JavaUtil::Collection" do
9898
subject{Java::JavaUtil::ArrayList.new(initial_array)}
9999

100-
context "when inspecting" do
100+
context "when inspecting a list" do
101101
let(:items) { [:a, {:b => :c}] }
102102
subject { java.util.ArrayList.new(items) }
103103

@@ -108,9 +108,20 @@
108108
it "should include the class name" do
109109
expect(subject.inspect).to include("ArrayList")
110110
end
111+
end
112+
113+
context "when inspecting a set" do
114+
let(:items) { [:foo, 'bar'] }
115+
subject { java.util.HashSet.new(items) }
116+
117+
it "should include the contents" do
118+
expect(subject.inspect).to include 'bar'
119+
end
120+
121+
it "should include the class name" do
122+
expect(subject.inspect).to include("HashSet")
111123

112-
it "should include the hash code of the collection" do
113-
expect(subject.inspect).to include(subject.hashCode.to_s)
124+
expect(java.util.TreeSet.new.inspect).to include("TreeSet")
114125
end
115126
end
116127

logstash-core/src/main/java/org/logstash/RubyJavaIntegration.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,6 @@ public static IRubyObject or(final ThreadContext context, final IRubyObject self
213213
return JavaUtil.convertJavaToUsableRubyObject(context.runtime, dup);
214214
}
215215

216-
@JRubyMethod
217-
public static IRubyObject inspect(final ThreadContext context, final IRubyObject self) {
218-
return RubyString.newString(context.runtime, new StringBuilder("<")
219-
.append(self.getMetaClass().name().asJavaString()).append(':')
220-
.append(self.hashCode()).append(' ').append(self.convertToArray().inspect())
221-
.append('>').toString()
222-
);
223-
}
224-
225216
private static boolean removeNilAndNull(final Collection<?> collection) {
226217
final boolean res = collection.removeAll(NIL_COLLECTION);
227218
return collection.removeAll(NULL_COLLECTION) || res;

0 commit comments

Comments
 (0)