001 // Protocol Buffers - Google's data interchange format
002 // Copyright 2008 Google Inc.
003 // http://code.google.com/p/protobuf/
004 //
005 // Licensed under the Apache License, Version 2.0 (the "License");
006 // you may not use this file except in compliance with the License.
007 // You may obtain a copy of the License at
008 //
009 // http://www.apache.org/licenses/LICENSE-2.0
010 //
011 // Unless required by applicable law or agreed to in writing, software
012 // distributed under the License is distributed on an "AS IS" BASIS,
013 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 // See the License for the specific language governing permissions and
015 // limitations under the License.
016
017 package org.fusesource.hawtbuf.proto;
018
019 import java.io.IOException;
020
021 /**
022 * Thrown when a protocol message being parsed is invalid in some way, e.g. it
023 * contains a malformed varint or a negative byte length.
024 *
025 * @author kenton@google.com Kenton Varda
026 */
027 public class InvalidProtocolBufferException extends IOException {
028 private static final long serialVersionUID = 5685337441004132240L;
029 private final Boolean eof;
030
031 public InvalidProtocolBufferException(String description) {
032 this(description, false);
033 }
034
035 public InvalidProtocolBufferException(String description, Boolean eof) {
036 super(description);
037 this.eof = eof;
038 }
039
040 public Boolean isEOF() {
041 return eof;
042 }
043
044 static InvalidProtocolBufferException truncatedMessage() {
045 return new InvalidProtocolBufferException("While parsing a protocol message, the input ended unexpectedly " + "in the middle of a field. This could mean either than the " + "input has been truncated or that an embedded message "
046 + "misreported its own length.");
047 }
048
049 static InvalidProtocolBufferException negativeSize() {
050 return new InvalidProtocolBufferException("CodedInputStream encountered an embedded string or message " + "which claimed to have negative size.");
051 }
052
053 static InvalidProtocolBufferException malformedVarint() {
054 return new InvalidProtocolBufferException("CodedInputStream encountered a malformed varint.");
055 }
056
057 static InvalidProtocolBufferException invalidTag() {
058 return new InvalidProtocolBufferException("Protocol message contained an invalid tag (zero).");
059 }
060
061 static InvalidProtocolBufferException invalidEndTag() {
062 return new InvalidProtocolBufferException("Protocol message end-group tag did not match expected tag.");
063 }
064
065 static InvalidProtocolBufferException invalidWireType() {
066 return new InvalidProtocolBufferException("Protocol message tag had invalid wire type.");
067 }
068
069 static InvalidProtocolBufferException recursionLimitExceeded() {
070 return new InvalidProtocolBufferException("Protocol message had too many levels of nesting. May be malicious. " + "Use CodedInputStream.setRecursionLimit() to increase the depth limit.");
071 }
072
073 static InvalidProtocolBufferException sizeLimitExceeded() {
074 return new InvalidProtocolBufferException("Protocol message was too large. May be malicious. " + "Use CodedInputStream.setSizeLimit() to increase the size limit.");
075 }
076 }