Skip to content

Commit

Permalink
Merge pull request #105 from yiduwangkai/master
Browse files Browse the repository at this point in the history
add IncompleteAnnotationException And AnnotationTypeMismatchException
  • Loading branch information
wongoo authored Jul 22, 2019
2 parents 8c3d0af + eb6f939 commit 85cc41b
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
3 changes: 3 additions & 0 deletions java_exception.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package hessian
import "github.com/dubbogo/hessian2/java_exception"

func init() {
RegisterPOJO(&java_exception.Method{})
RegisterPOJO(&java_exception.Class{})
RegisterPOJO(&java_exception.Throwable{})
RegisterPOJO(&java_exception.Exception{})
Expand Down Expand Up @@ -105,4 +106,6 @@ func init() {
RegisterPOJO(&java_exception.MissingFormatArgumentException{})
RegisterPOJO(&java_exception.MissingFormatWidthException{})
RegisterPOJO(&java_exception.DubboGenericException{})
RegisterPOJO(&java_exception.IncompleteAnnotationException{})
RegisterPOJO(&java_exception.AnnotationTypeMismatchException{})
}
37 changes: 37 additions & 0 deletions java_exception/annotation_type_mismatch_exception.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2016-2019 yiduwangkai@gmail.com
//
// Licensed 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 java_exception

type AnnotationTypeMismatchException struct {
SerialVersionUID int64
DetailMessage string
StackTrace []StackTraceElement
FoundType string
Element Method
SuppressedExceptions []Throwabler
Cause Throwabler
}

func NewAnnotationTypeMismatchException(detailMessage string) *AnnotationTypeMismatchException {
return &AnnotationTypeMismatchException{DetailMessage: detailMessage, StackTrace: []StackTraceElement{}}
}

func (e AnnotationTypeMismatchException) Error() string {
return e.DetailMessage
}

func (AnnotationTypeMismatchException) JavaClassName() string {
return "java.lang.annotation.AnnotationTypeMismatchException"
}
9 changes: 9 additions & 0 deletions java_exception/exception.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ type Class struct {
Name string
}

type Method struct {
Name string
}


func (Method) JavaClassName() string {
return "java.lang.reflect.Method"
}

func (Class) JavaClassName() string {
return "java.lang.Class"
}
37 changes: 37 additions & 0 deletions java_exception/incomplete_annotation_exception.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2016-2019 yiduwangkai@gmail.com
//
// Licensed 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 java_exception

type IncompleteAnnotationException struct {
SerialVersionUID int64
DetailMessage string
StackTrace []StackTraceElement
ElementName string
AnnotationType Class
SuppressedExceptions []Throwabler
Cause Throwabler
}

func NewIncompleteAnnotationException(detailMessage string) *IncompleteAnnotationException {
return &IncompleteAnnotationException{DetailMessage: detailMessage, StackTrace: []StackTraceElement{}}
}

func (e IncompleteAnnotationException) Error() string {
return e.DetailMessage
}

func (IncompleteAnnotationException) JavaClassName() string {
return "java.lang.annotation.IncompleteAnnotationException"
}
2 changes: 2 additions & 0 deletions java_exception_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func TestException(t *testing.T) {
doTestException(t, "throw_MissingFormatArgumentException", "Format specifier 'MissingFormatArgumentException'")
doTestException(t, "throw_MissingFormatWidthException", "MissingFormatWidthException")
doTestException(t, "throw_DubboGenericException", "DubboGenericException")
doTestException(t, "throw_IncompleteAnnotationException", "java.lang.Override missing element IncompleteAnnotationException")
doTestException(t, "throw_AnnotationTypeMismatchException", "Incorrectly typed data found for annotation element null (Found data of type AnnotationTypeMismatchException)")
}

func doTestException(t *testing.T, method, content string) {
Expand Down
11 changes: 11 additions & 0 deletions test_hessian/src/main/java/test/TestThrowable.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.alibaba.dubbo.rpc.service.GenericException;

import java.io.*;
import java.lang.annotation.AnnotationTypeMismatchException;
import java.lang.annotation.IncompleteAnnotationException;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.instrument.UnmodifiableClassException;
import java.lang.invoke.LambdaConversionException;
Expand Down Expand Up @@ -395,4 +397,13 @@ public static Object throw_MissingFormatWidthException() {
public static Object throw_DubboGenericException() {
return new GenericException("DubboGenericExceptionClass","DubboGenericException");
}

public static Object throw_IncompleteAnnotationException() {
return new IncompleteAnnotationException(Override.class, "IncompleteAnnotationException");
}

public static Object throw_AnnotationTypeMismatchException() {
return new AnnotationTypeMismatchException(Override.class.getEnclosingMethod(), "AnnotationTypeMismatchException");
}

}

0 comments on commit 85cc41b

Please sign in to comment.