Orika not able to map when the application is running on Jetty - java

I am using Orika to map between two java objects. When I run junit tests it works fine - the objects are mapped correctly, but when I execute the code running on jetty I get this exception:
...
Caused by: java.lang.NoClassDefFoundError: Loracle/dms/console/DMSConsole;
at java.lang.Class.getDeclaredFields0(Native Method) ~[na:1.8.0_45]
at java.lang.Class.privateGetDeclaredFields(Class.java:2583) ~[na:1.8.0_45]
at java.lang.Class.getDeclaredFields(Class.java:1916) ~[na:1.8.0_45]
at com.carrotsearch.sizeof.RamUsageEstimator.createCacheEntry(RamUsageEstimator.java:568) ~[java-sizeof-0.0.4.jar:na]
at com.carrotsearch.sizeof.RamUsageEstimator.measureSizeOf(RamUsageEstimator.java:532) ~[java-sizeof-0.0.4.jar:na]
at com.carrotsearch.sizeof.RamUsageEstimator.sizeOfAll(RamUsageEstimator.java:380) ~[java-sizeof-0.0.4.jar:na]
at com.carrotsearch.sizeof.RamUsageEstimator.sizeOfAll(RamUsageEstimator.java:361) ~[java-sizeof-0.0.4.jar:na]
at ma.glasnost.orika.StateReporter.humanReadableSizeInMemory(StateReporter.java:48) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.impl.DefaultMapperFactory.reportCurrentState(DefaultMapperFactory.java:1547) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.StateReporter.reportCurrentState(StateReporter.java:33) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.impl.ExceptionUtility.decorate(ExceptionUtility.java:65) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.impl.MapperFacadeImpl.resolveMappingStrategy(MapperFacadeImpl.java:209) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.impl.DefaultBoundMapperFacade$BoundStrategyCache.getStrategy(DefaultBoundMapperFacade.java:259) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.impl.DefaultBoundMapperFacade.map(DefaultBoundMapperFacade.java:137) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.generated.LocalDate_LocalDate_ObjectFactory1257832766063212584156506661$3.create(LocalDate_LocalDate_ObjectFactory1257832766063212584156506661$3.java) ~[na:na]
at ma.glasnost.orika.impl.mapping.strategy.InstantiateAndUseCustomMapperStrategy.getInstance(InstantiateAndUseCustomMapperStrategy.java:55) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.impl.mapping.strategy.UseCustomMapperStrategy.map(UseCustomMapperStrategy.java:61) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.impl.DefaultBoundMapperFacade.map(DefaultBoundMapperFacade.java:137) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.generated.Orika_TransactionType_Transaction_Mapper12578333614376$1.mapAtoB(Orika_TransactionType_Transaction_Mapper12578333614376$1.java) ~[na:na]
at ma.glasnost.orika.impl.mapping.strategy.UseCustomMapperStrategy.map(UseCustomMapperStrategy.java:67) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:378) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:367) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:408) ~[orika-core-1.4.5.jar:na]
at ma.glasnost.orika.impl.ConfigurableMapper.map(ConfigurableMapper.java:158) ~[orika-core-1.4.5.jar:na]
...
Caused by: java.lang.ClassNotFoundException: oracle.dms.console.DMSConsole
...
I have attempted to create the mapping code in several ways: (1) extending ConfigurableMapper and (2) setting the facade up (similar to this):
MapperFactory factory = new DefaultMapperFactory.Builder().build();
factory.registerClassMap(factory.classMap(Order.class,OrderDTO.class)
.field("product.state.type.label", "stateLabel")
.field("product.name", "productName").toClassMap());
MapperFacade mapper = factory.getMapperFacade();
The result is always the same, it works fine when I run my junit tests, but it fails when the same code runs as part of a service inside jetty.
I can't seem to understand what DMSConsole has to do with the mapping.
update
somehow related to joda DateTime mapping, as the project has moved to java.time, this is no longer an issue.
removing this solved the issue:
factory.getConverterFactory().registerConverter(new PassThroughConverter(DateTime.class));
I still don't see the connection to the exception, so I may be missing something, but no longer an issue.

You have a problem of class visibility, so please, can you disable dump state on exception by using MapperFactory.dumpStateOnException(false) and resend your logs.

Related

Getting java.lang.NoSuchMethodException: io.jsonwebtoken.impl.crypto.MacProvider.generateKey only in case of jUnits

I have recently started getting following exception, only when junits are being run. In normal flow, the method runs fine. (In fact even the jUnits used to work fine till some time back)
java.lang.NoSuchMethodException:
io.jsonwebtoken.impl.crypto.MacProvider.generateKey(io.jsonwebtoken.SignatureAlgorithm)
Following is the method:
public static String generateDummyJWT(String userName)
{
return Jwts.builder().claim("user_name", StringUtils.defaultString(userName)).setAudience("client1").signWith(Keys.secretKeyFor(SignatureAlgorithm.HS384)).compact();
}
And jjwt versions:
Following is the complete stack trace:
Caused by: java.lang.IllegalStateException: Unable to invoke class
method io.jsonwebtoken.impl.crypto.MacProvider#generateKey. Ensure
the necessary implementation is in the runtime classpath. at
io.jsonwebtoken.lang.Classes.invokeStatic(Classes.java:202) at
io.jsonwebtoken.security.Keys.secretKeyFor(Keys.java:121) at
com.random.util.ServiceSpecificUtil.generateDummyJWT(ServiceSpecificUtil.java:143)
at
com.random.util.ServiceConstants.(ServiceConstants.java:203)
at com.random.MyClass.isUserBranch(MyClass.java:67) at
com.random.MyClass.validName(MyClass.java:93) at
com.random.MyClass.preConditionCheck(MyClass.java:82) at
com.random.MyClass.get(MyClass.java:46) at
com.random.MyClass2.evaluateExpression(MyClass2.java:218) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl$1.invoke(MockitoMethodInvocationControl.java:243)
at
org.mockito.internal.invocation.realmethod.CleanTraceRealMethod.invoke(CleanTraceRealMethod.java:30)
at
org.mockito.internal.invocation.InvocationImpl.callRealMethod(InvocationImpl.java:112)
at
org.mockito.internal.stubbing.answers.CallsRealMethods.answer(CallsRealMethods.java:41)
at
org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:93)
at
org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl.performIntercept(MockitoMethodInvocationControl.java:266)
at
org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl.invoke(MockitoMethodInvocationControl.java:192)
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:132)
at org.powermock.core.MockGateway.methodCall(MockGateway.java:63) at
com.random.MyClass2.evaluateExpression(MyClass2.java) at
com.random.MyClass2.isPermitted(MyClass2.java:107) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl$1.invoke(MockitoMethodInvocationControl.java:243)
at
org.mockito.internal.invocation.realmethod.CleanTraceRealMethod.invoke(CleanTraceRealMethod.java:30)
at
org.mockito.internal.invocation.InvocationImpl.callRealMethod(InvocationImpl.java:112)
at
org.mockito.internal.stubbing.answers.CallsRealMethods.answer(CallsRealMethods.java:41)
at
org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:93)
at
org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl.performIntercept(MockitoMethodInvocationControl.java:266)
at
org.powermock.api.mockito.internal.invocation.MockitoMethodInvocationControl.invoke(MockitoMethodInvocationControl.java:192)
... 32 more Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
io.jsonwebtoken.lang.Classes.invokeStatic(Classes.java:198) ... 66
more Caused by: java.lang.IllegalStateException: The HmacSHA384
algorithm is not available. This should never happen on JDK 7 or
later - please report this to the JJWT developers. at
io.jsonwebtoken.impl.crypto.MacProvider.generateKey(MacProvider.java:94)
at
io.jsonwebtoken.impl.crypto.MacProvider.generateKey(MacProvider.java:63)
... 71 more Caused by: java.security.NoSuchAlgorithmException:
HmacSHA384 KeyGenerator not available at
javax.crypto.KeyGenerator.(KeyGenerator.java:169) at
javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:223) at
io.jsonwebtoken.impl.crypto.MacProvider.generateKey(MacProvider.java:92)
... 72 more
I was able to resolve my problem.
Someone in the team had added the call to above function while initializing a static final variable like this:
public static String TOKEN_GUEST = ServiceSpecificUtil.generateDummyJWT(USERNAME);
Now, it seems that access to the java.security packges generally does not work well with PowerMock due to heavy use of reflections & byte code manipulations:
Although I had referred this SO post and tried the suggested solution of using
#PowerMockIgnore like:
#PowerMockIgnore({"org.apache.http.conn.ssl.*", "javax.net.ssl.*" , "javax.crypto.*"})
and that might be helpful in preventing errors when above function was called from another function. But it was not preventing errors in static variable initialization.
public static String TOKEN_GUEST = ServiceSpecificUtil.generateDummyJWT(USERNAME);
I will update this post when I dig deeper as to why the error was coming only in case of static variable initialization and not when ServiceSpecificUtil.generateDummyJWT(USERNAME) was being called from another function.

Docusignapi java.lang.NoSuchMethodError for createEnvelope

I'm trying to integrate the example code of the JAVA SDK 2.1 of Docusign in my application.
The authentification process passed well but when calling the following code :
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
envelopesApi.createEnvelope("1111111", envelopeDefinition);
An exception is recieved :
Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.getConfig()Lcom/fasterxml/jackson/databind/SerializationConfig;
at com.fasterxml.jackson.jaxrs.json.JsonEndpointConfig.forWriting(JsonEndpointConfig.java:45)
at com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider._configForWriting(JacksonJsonProvider.java:223)
at com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider._configForWriting(JacksonJsonProvider.java:45)
at com.fasterxml.jackson.jaxrs.base.ProviderBase._configForWriting(ProviderBase.java:481)
at com.fasterxml.jackson.jaxrs.base.ProviderBase._endpointForWriting(ProviderBase.java:694)
at com.fasterxml.jackson.jaxrs.base.ProviderBase.writeTo(ProviderBase.java:565)
at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:300)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:217)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:153)
at com.sun.jersey.api.client.Client.handle(Client.java:652)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)
at com.docusign.esign.client.ApiClient.getAPIResponse(ApiClient.java:1125)
at com.docusign.esign.client.ApiClient.invokeAPI(ApiClient.java:1158)
at com.docusign.esign.api.EnvelopesApi.createEnvelope(EnvelopesApi.java:764)
at com.docusign.esign.api.EnvelopesApi.createEnvelope(EnvelopesApi.java:714)
at com.hlf.plateforme.webservice.DocusignWrapper.sendEnvelope(DocusignWrapper.java:160)
at com.hlf.plateforme.web.action.demande.EcontratAction.esignature(EcontratAction.java:246)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
... 36 more
Can someone assist ?
I'm answering my questions in case it can help someone :)
Finally it was a version problem of one of the dependencies....
com.fasterxml.jackson.core
I updated the version to the most recent and it solved the problem.

Reload SSL context used by Spring Kafka at runtime

What is the recommended way to make Spring Kafka reload SSL context?
I have a requirement to insert new certificates into the trust store that my Kafka producer uses without any downtime.
However what I have found is that once the application is started and a Kafka producer is created, an instance of SSLContext is created and cached. There is a way to reconfigure this but the only way I have found so far is to destroy any existing producers by invoking the destroy method on DefaultKafkaProducerFactory (after certificate renewal) which causes any subsequent calls to KafkaTemplate.send to force a new producer to be created which in turn reloads the SSL context.
I feel this is like using a sledgehammer to solve this problem and there might be a more elegant solution. I have also noticed that if I call destroy when there are messages being sent, I get the below exception which doesn't look very positive when we cannot afford to lose any events.
java.util.concurrent.CompletionException: org.apache.kafka.common.KafkaException: Producer closed while send in progress
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
at java.util.concurrent.CompletableFuture$AsyncSupply.run$$$capture(CompletableFuture.java:1592)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java)
at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: org.apache.kafka.common.KafkaException: Producer closed while send in progress
at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:826)
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:803)
at org.springframework.kafka.core.DefaultKafkaProducerFactory$CloseSafeProducer.send(DefaultKafkaProducerFactory.java:444)
at org.springframework.kafka.core.KafkaTemplate.doSend(KafkaTemplate.java:372)
at org.springframework.kafka.core.KafkaTemplate.send(KafkaTemplate.java:190)
at org.springframework.kafka.core.KafkaOperations$send.call(Unknown Source)
at com.example.event.publisher.kafka.KafkaEventPublisher.doPublish(KafkaEventPublisher.groovy:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:352)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:68)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:177)
at com.example.event.publisher.kafka.KafkaEventPublisher$_publish_closure1.doCall(KafkaEventPublisher.groovy:47)
at com.example.event.publisher.kafka.KafkaEventPublisher$_publish_closure1.doCall(KafkaEventPublisher.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at groovy.lang.Closure.call(Closure.java:418)
at org.codehaus.groovy.runtime.ConvertedClosure.invokeCustom(ConvertedClosure.java:54)
at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:124)
at com.sun.proxy.$Proxy103.get(Unknown Source)
at java.util.concurrent.CompletableFuture$AsyncSupply.run$$$capture(CompletableFuture.java:1590)
... 6 common frames omitted
Caused by: org.apache.kafka.common.KafkaException: Requested metadata update after close
at org.apache.kafka.clients.Metadata.awaitUpdate(Metadata.java:200)
at org.apache.kafka.clients.producer.KafkaProducer.waitOnMetadata(KafkaProducer.java:938)
at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:823)
... 37 common frames omitted
It looks like simply resetting the config for certain values will trigger a rebuild on the SSL engine factory. They even call out file key config that would cause a hot reload.
link
Spring Kafka 2.6.5, Kafka 2.4.1, I use KafkaProducerFactory.reset() instead.
#Autowired
private final KafkaTemplate<String, byte[]> kafkaTemplate;
private void reloadProducer() {
kafkaTemplate.getProducerFactory().reset();
}
Next time send() is called, Spring will recreate a brand spanking new KafkaConsumer with the new certificate.

Protobuf 3.0 Map causes java.lang.ExceptionInInitializerError: null in J9VM

Here is my proto:
proto
message TransactionRecord {
……
map<string, string> parameters = 19;
……
}
Then, I use following code to get a builder
java
final TransactionRecord.Builder metaDataBuilder = requestBuilder.getMetaData().toBuilder();
This code run fine in many JVMs, but fail in J9VM
Exception as following:
java.lang.ExceptionInInitializerError: null
at java.lang.J9VMInternals.initialize(J9VMInternals.java:222) ~[na:1.6.0]
at com.blueware.deps.com.google.protobuf.MapField.mergeFrom(MapField.java:204) ~[oneapm.jar:2.0]
at com.blueware.monitor.collector.grpc.TransactionRecord$Builder.mergeFrom(TransactionRecord.java:1323) ~[oneapm.jar:2.0]
at com.blueware.monitor.collector.grpc.TransactionRecord.toBuilder(TransactionRecord.java:1062) ~[oneapm.jar:2.0]
at com.blueware.monitor.transaction.TransactionDataCompressorFactoryService.compressMetaData(TransactionDataCompressorFactoryS
ervice.java:401) ~[oneapm.jar:2.0]
at com.blueware.monitor.transaction.TransactionDataCompressorFactoryService.compress(TransactionDataCompressorFactoryService.j
at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:361) [weblogic.jar:1
0.3.6.0]
at weblogic.management.deploy.internal.ConfiguredDeployments.deployPreStandbyInternalApps(ConfiguredDeployments.java:85) [webl
ogic.jar:10.3.6.0]
at weblogic.management.deploy.internal.DeploymentServerService.deployPreStandbyInternalApps(DeploymentServerService.java:168)
[weblogic.jar:10.3.6.0]
at weblogic.management.deploy.internal.DeploymentPreStandbyServerService.start(DeploymentPreStandbyServerService.java:27) [web
logic.jar:10.3.6.0]
at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64) [weblogic.jar:10.3.6.0]
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256) [com.bea.core.weblogic.workmanager_1.11.0.0.jar:1.11.0.0]
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221) [com.bea.core.weblogic.workmanager_1.11.0.0.jar:1.11.0.0]
Caused by: java.lang.UnsupportedOperationException: null
at com.blueware.deps.com.google.protobuf.MapFieldLite.ensureMutable(MapFieldLite.java:221) ~[oneapm.jar:2.0]
at com.blueware.deps.com.google.protobuf.MapFieldLite.putAll(MapFieldLite.java:99) ~[oneapm.jar:2.0]
at java.util.LinkedHashMap.<init>(LinkedHashMap.java:112) ~[na:na]
at com.blueware.deps.com.google.protobuf.MapFieldLite.<init>(MapFieldLite.java:56) ~[oneapm.jar:2.0]
at com.blueware.deps.com.google.protobuf.MapFieldLite.<clinit>(MapFieldLite.java:61) ~[oneapm.jar:2.0]
at java.lang.J9VMInternals.initializeImpl(Native Method) ~[na:1.6.0]
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200) ~[na:1.6.0]
... 45 common frames omitted
I have tried to remove map parameters for define, it goes fine.
Instead, I use final TransactionRecord.Builder metaDataBuilder = requestBuilder.getMetaDataBuilder();, that can't fix this issue. still failure on J9VM
How did this bug happen?
Is this a bug for map?
I have solve my problem. Have been confirmed, this is protobuf bug, when it's running on J9VM.
When static field EMPTY_MAP_FIELD in MapFieldLite is initilized on IBM J9, putAll which is overrided and calls ensureMutable. And ensureMutable is called in its super class LinkedHashMap, that causes UnsupportedOperationException is thrown, when isMutable has set to false at that time.
More info, you can read this RP.
RP has been merged by protobuf-java, RP is here

What are GeneratedMethodAccessor1,2,etc and why might they not be found?

I'm getting stack traces like this:
java.lang.NoClassDefFoundError: sun/reflect/GeneratedMethodAccessor1
at sun.reflect.GeneratedMethodAccessor1.<clinit>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:381)
at java.security.AccessController.doPrivileged(Native Method)
at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:377)
at sun.reflect.MethodAccessorGenerator.generateMethod(MethodAccessorGenerator.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:28)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at edu.tufts.cs.testsim.LogicalProcess.dispatchMessage(LogicalProcess.java:214)
at edu.tufts.cs.testsim.LogicalProcess.processForward(LogicalProcess.java:287)
at edu.tufts.cs.testsim.LogicalProcess.doOperation(LogicalProcess.java:423)
at edu.tufts.cs.testsim.LogicalProcess.run(LogicalProcess.java:434)
at java.lang.Thread.run(Thread.java:637)
Caused by: java.lang.ClassNotFoundException: sun.reflect.GeneratedMethodAccessor1
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:288)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
... 19 more
What are GeneratedMethodAccessor1, GeneratedMethodAccessor2, GeneratedMethodAccessorN and what might be causing them to not be found? I am doing some byte code rewriting at run time, but only before the class is loaded, and the first several calls through reflection work fine. I'm wondering if this is happening after the JIT compiler gets a hold of my code, but I don't even have a very good idea of how to start debugging this.
GeneratedMethodAccessor### are classes generated at runtime by the reflection implementation to call methods and constructors. This form a bytecode bridge from instances of Method or Constructor to the actual method or constructor. More information is available in the source code.
Deserialisation also does something similar, sharing some of the same mechanism, to invoke the most derived non-Serializable constructor.

Categories