Remove UnknownNamedObjectException (#53105)
This was originally thrown from NamedXContentRegistry#parseNamedObject() but that method now throws a NamedObjectNotFoundException, so this is unused.
This commit is contained in:
parent
e46bb54c7b
commit
3cd4b97618
|
@ -1007,8 +1007,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
org.elasticsearch.tasks.TaskCancelledException::new, 146, UNKNOWN_VERSION_ADDED),
|
||||
SHARD_LOCK_OBTAIN_FAILED_EXCEPTION(org.elasticsearch.env.ShardLockObtainFailedException.class,
|
||||
org.elasticsearch.env.ShardLockObtainFailedException::new, 147, UNKNOWN_VERSION_ADDED),
|
||||
UNKNOWN_NAMED_OBJECT_EXCEPTION(org.elasticsearch.common.xcontent.UnknownNamedObjectException.class,
|
||||
org.elasticsearch.common.xcontent.UnknownNamedObjectException::new, 148, UNKNOWN_VERSION_ADDED),
|
||||
// 148 was UnknownNamedObjectException
|
||||
TOO_MANY_BUCKETS_EXCEPTION(MultiBucketConsumerService.TooManyBucketsException.class,
|
||||
MultiBucketConsumerService.TooManyBucketsException::new, 149, Version.V_6_2_0),
|
||||
COORDINATION_STATE_REJECTED_EXCEPTION(org.elasticsearch.cluster.coordination.CoordinationStateRejectedException.class,
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.xcontent;
|
||||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* Thrown when {@link NamedXContentRegistry#parseNamedObject(Class, String, XContentParser, Object)} is called with an unregistered
|
||||
* name. When this bubbles up to the rest layer it is converted into a response with {@code 400 BAD REQUEST} status.
|
||||
*/
|
||||
public class UnknownNamedObjectException extends ParsingException {
|
||||
private final String categoryClass;
|
||||
private final String name;
|
||||
|
||||
public UnknownNamedObjectException(XContentLocation contentLocation, Class<?> categoryClass, String name) {
|
||||
super(contentLocation, "Unknown " + categoryClass.getSimpleName() + " [" + name + "]");
|
||||
this.categoryClass = requireNonNull(categoryClass, "categoryClass is required").getName();
|
||||
this.name = requireNonNull(name, "name is required");
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public UnknownNamedObjectException(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
categoryClass = in.readString();
|
||||
name = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeString(categoryClass);
|
||||
out.writeString(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Category class that was missing a parser. This is a String instead of a class because the class might not be on the classpath
|
||||
* of all nodes or it might be exclusive to a plugin or something.
|
||||
*/
|
||||
public String getCategoryClass() {
|
||||
return categoryClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the missing parser.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -55,7 +55,6 @@ import org.elasticsearch.common.transport.TransportAddress;
|
|||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.util.CancellableThreadsTests;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.UnknownNamedObjectException;
|
||||
import org.elasticsearch.common.xcontent.XContentLocation;
|
||||
import org.elasticsearch.env.ShardLockObtainFailedException;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
@ -809,7 +808,7 @@ public class ExceptionSerializationTests extends ESTestCase {
|
|||
ids.put(145, org.elasticsearch.ElasticsearchStatusException.class);
|
||||
ids.put(146, org.elasticsearch.tasks.TaskCancelledException.class);
|
||||
ids.put(147, org.elasticsearch.env.ShardLockObtainFailedException.class);
|
||||
ids.put(148, UnknownNamedObjectException.class);
|
||||
ids.put(148, null);
|
||||
ids.put(149, MultiBucketConsumerService.TooManyBucketsException.class);
|
||||
ids.put(150, CoordinationStateRejectedException.class);
|
||||
ids.put(151, SnapshotInProgressException.class);
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.xcontent;
|
||||
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class UnknownNamedObjectExceptionTests extends ESTestCase {
|
||||
public void testRoundTrip() throws IOException {
|
||||
XContentLocation location = new XContentLocation(between(1, 1000), between(1, 1000));
|
||||
UnknownNamedObjectException created = new UnknownNamedObjectException(location, UnknownNamedObjectExceptionTests.class,
|
||||
randomAlphaOfLength(5));
|
||||
UnknownNamedObjectException roundTripped;
|
||||
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
created.writeTo(out);
|
||||
try (StreamInput in = out.bytes().streamInput()) {
|
||||
roundTripped = new UnknownNamedObjectException(in);
|
||||
}
|
||||
}
|
||||
assertEquals(created.getMessage(), roundTripped.getMessage());
|
||||
assertEquals(created.getLineNumber(), roundTripped.getLineNumber());
|
||||
assertEquals(created.getColumnNumber(), roundTripped.getColumnNumber());
|
||||
assertEquals(created.getCategoryClass(), roundTripped.getCategoryClass());
|
||||
assertEquals(created.getName(), roundTripped.getName());
|
||||
}
|
||||
|
||||
public void testStatusCode() {
|
||||
XContentLocation location = new XContentLocation(between(1, 1000), between(1, 1000));
|
||||
UnknownNamedObjectException e = new UnknownNamedObjectException(location, UnknownNamedObjectExceptionTests.class,
|
||||
randomAlphaOfLength(5));
|
||||
assertEquals(RestStatus.BAD_REQUEST, e.status());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue