Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException while ClassReader parses Annotation arguments of type boolean.class #562

Closed
MarkusLutum opened this issue Oct 29, 2018 · 2 comments
Assignees
Labels

Comments

@MarkusLutum
Copy link

MarkusLutum commented Oct 29, 2018

  • Version of JMockit that was used:
    1.41 and 1.43
    maven 3.3.9 or 3.2.5
    Java 1.8.0_181

  • Description of the problem:
    A test adds an expectation which involves a class called Person.class
    This has a property like this
    @RestApiField(metaDataName = FieldDefinitionConsts.FIELD_DEFINITION_CAN_BE_USER, getterMethod = "isCanBeUser", fieldType = boolean.class)
    private String canBeUser = StringUtil.FALSE;
    The property fieldtype is defined as
    Class<?> fieldType() default Null.class;

This results in an IllegalArgumentException
java.lang.IllegalArgumentException: Invalid type descriptor: Z
if the test is executed via maven (see stack below)
strangely in my Ecplise IDE it works.

If I change the fieldType property to Boolean.class it works.
In case of the primitive class type boolean.class the internal "strings" array contains this Z (which indicated a primitive boolean):
... canBeUser, CanBeUser, getterMethod, isCanBeUser, fieldType, Z, canbeuser, ....

Should the method
mockit.asm.ReferenceType.getReferenceType(char[], int)
Also support the primitive Class types

The Stack
Thread [main] (Suspended (exception IllegalArgumentException)) ReferenceType.getReferenceType(char[], int) line: 54 ReferenceType.createFromTypeDescriptor(String) line: 38 AnnotationReader.readClassInfo(String, AnnotationVisitor) line: 102 AnnotationReader.readAnnotationValue(String, AnnotationVisitor) line: 57 AnnotationReader.readAnnotationValues(int, boolean, AnnotationVisitor) line: 33 AnnotationReader.readAnnotationValues(boolean, AnnotationVisitor) line: 27 AnnotationReader.readNamedAnnotationValues(int, AnnotationVisitor) line: 21 FieldReader(AnnotatedReader).readAnnotationValues(AnnotationVisitor) line: 80 FieldReader(AnnotatedReader).readAnnotations(BaseWriter) line: 72 FieldReader.readField() line: 40 FieldReader.readFields() line: 23 ClassReader.readFieldsAndMethods() line: 220 ClassReader.accept(ClassVisitor, int) line: 121 ClassReader.accept(ClassVisitor) line: 94 CascadingTypeRedefinition(BaseTypeRedefinition).redefineClass(Class<?>, ClassReader, MockedClassModifier) line: 211 CascadingTypeRedefinition(BaseTypeRedefinition).redefineClassAndItsSuperClasses(Class<?>) line: 188 CascadingTypeRedefinition(BaseTypeRedefinition).redefineClassAndItsSuperClasses(Class<?>) line: 204 CascadingTypeRedefinition(BaseTypeRedefinition).redefineMethodsAndConstructorsInTargetType() line: 175 CascadingTypeRedefinition(BaseTypeRedefinition).redefineTargetClassAndCreateInstanceFactory(Type) line: 251 CascadingTypeRedefinition(BaseTypeRedefinition).redefineType(Type) line: 67 CascadingTypeRedefinition.redefineType() line: 21 MockedTypeCascade.createNewCascadedInstanceOrUseNonCascadedOneIfAvailable(String, Type) line: 274 MockedTypeCascade.getCascadedInstance(String, String, Object) line: 224 MockedTypeCascade.getMock(String, String, Object, String, String) line: 98 ExpectedInvocation.getDefaultValueForReturnType() line: 379 RecordPhase.handleInvocation(Object, int, String, String, String, boolean, Object[]) line: 57 RecordAndReplayExecution.recordOrReplay(Object, int, String, String, String, int, Object[]) line: 170 $Impl_PersonLister.findVisitorByVisit(VisitDetails) line: not available VisitConverterTest$9.<init>(VisitConverterTest, VisitDetails, Visitor, AuthorisationOnline) line: 470 VisitConverterTest.viewTestDetailsWithAuthorizationsOneEntry() line: 468 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: 62 DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43 Method.invoke(Object, Object...) line: 498 FrameworkMethod$1.runReflectiveCall() line: 50 FrameworkMethod$1(ReflectiveCallable).run() line: 12 FrameworkMethod.invokeExplosively(Object, Object...) line: 47 JUnit4TestRunnerDecorator.executeTestMethod(FakeInvocation, Object, Object...) line: 154 JUnit4TestRunnerDecorator.invokeExplosively(FakeInvocation, Object, Object...) line: 70 FakeFrameworkMethod.invokeExplosively(Invocation, Object, Object...) line: 33 <unknown receiving type>(FrameworkMethod).invokeExplosively(Object, Object...) line: 47 InvokeMethod.evaluate() line: 17 RunBefores.evaluate() line: 26 JMockit(ParentRunner<T>).runLeaf(Statement, Description, RunNotifier) line: 325 JMockit(BlockJUnit4ClassRunner).runChild(FrameworkMethod, RunNotifier) line: 78 JMockit(BlockJUnit4ClassRunner).runChild(Object, RunNotifier) line: 57 ParentRunner$3.run() line: 290 ParentRunner$1.schedule(Runnable) line: 71 JMockit(ParentRunner<T>).runChildren(RunNotifier) line: 288 ParentRunner<T>.access$000(ParentRunner, RunNotifier) line: 58 ParentRunner$2.evaluate() line: 268 RunBefores.evaluate() line: 26 JMockit(ParentRunner<T>).run(RunNotifier) line: 363 JUnit4Provider.execute(Class<?>, Notifier, Filter) line: 365 JUnit4Provider.executeWithRerun(Class<?>, Notifier) line: 273 JUnit4Provider.executeTestSet(Class<?>, RunListener, Notifier) line: 238 JUnit4Provider.invoke(Object) line: 159 ForkedBooter.invokeProviderInSameClassLoader(ForkingReporterFactory) line: 383 ForkedBooter.runSuitesInProcess() line: 344 ForkedBooter.execute() line: 125 ForkedBooter.main(String...) line: 417

@rliesenfeld
Copy link
Member

Example test?

@MarkusLutum
Copy link
Author

I quickly created a testcase which reflects our environment.
Within the latest jmockit checkout execution fails (also in my IDE now :-) )
BooleanPrimitiveTest.zip
Thx for support
Markus Lutum

@rliesenfeld rliesenfeld self-assigned this Oct 31, 2018
@jmockit jmockit locked and limited conversation to collaborators Apr 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants