CompletableFuture.isDone blocks CrudRepository.save(); - spring

I'm trying to store an entity in my database in an async method by returning a CompletableFuture<>. The code works fine as long as I do not check the state of the future (e.g isComplete() or .get()).
CompletableFuture<Product> working = serviceTest.test("working");
The above example works, the product is stored in the database.
#Async
public CompletableFuture<Product> test(String name)
{
Product p = new Product();
p.setId(new Random().nextInt(500000));
p.setName(name);
logger.info("Saving "+ name);
p = productRepository.save(p);
logger.info("finished " + name);
return CompletableFuture.completedFuture(p);
}
However, as soon as I change the code to for example
CompletableFuture<Product> notWorking = serviceTest.test("notWorking");
notWorking.get();
The entity is not saved and the code freezes at 'productRepository.save(p);'.
What is the correct way to save entities in an async method? Note that this is a simplified example and in the real scenario the test function is a long running operation to fetch a list of products from an external server.
The not explainable issue for me is that a simple method to get the state of the future blocks the saving of my entity.
I extracted a thread dump when the deadlock occurs. This is the relevant part
"MigrationTask-1" #19 prio=5 os_prio=0 tid=0x00007fbdd4bcd800 nid=0x16ea waiting for monitor entry [0x00007fbda9274000]
java.lang.Thread.State: BLOCKED (on object monitor)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:187)
- waiting to lock <0x00000000850ab208> (a java.util.concurrent.ConcurrentHashMap)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:486)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:432)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:403)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:389)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:177)
at org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils.qualifiedBeanOfType(BeanFactoryAnnotationUtils.java:89)
at org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils.qualifiedBeanOfType(BeanFactoryAnnotationUtils.java:66)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineQualifiedTransactionManager(TransactionAspectSupport.java:382)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineTransactionManager(TransactionAspectSupport.java:363)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy96.save(Unknown Source)

Related

Is #OnWebSocketClose always gets called ? I am getting #onwebsocketerror and #onwebsocketclose is not getting called

Is #onwebsocketclose always gets called ? I am getting #onwebsocketerror and #onwebsocketclose is not getting called .
There might be some broken pipe connection .
StackTrace :
org.eclipse.jetty.io.EofException: null
at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:283) ~[application.jar:?]
at org.eclipse.jetty.io.WriteFlusher.flush(WriteFlusher.java:422) ~[application.jar:?]
at org.eclipse.jetty.io.WriteFlusher.completeWrite(WriteFlusher.java:378) ~[application.jar:?]
at org.eclipse.jetty.io.ChannelEndPoint$3.run(ChannelEndPoint.java:132) ~[application.jar:?]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) ~[application.jar:?]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) ~[application.jar:?]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) ~[application.jar:?]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) ~[application.jar:?]
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367) ~[application.jar:?]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782) ~[application.jar:?]
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918) ~[application.jar:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
Caused by: java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[?:1.8.0_111]
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) ~[?:1.8.0_111]
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) ~[?:1.8.0_111]
at sun.nio.ch.IOUtil.write(IOUtil.java:65) ~[?:1.8.0_111]
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)~[?:1.8.0_111]
at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:261) ~[application.jar:?]
the Close method is called for WebSocket handshake completion or abnormal completion.
I/O errors, idle timeouts, harsh disconnects, and other errors are on the Error method.
Any event on onClose() or onError() signals the end of your session.
Exceptional closures (throwables) are racy on which of the 2 application event methods are called.
Some behaviors:
We try to notify onClose() only once.
We try to notify onError() only once.
If onClose() is called, onError() will not be called.
If onError() is called, onClose() will not be called.
If the closure is determined to be from an exception, then:
the exception is logged on DEBUG level
the application onError() is called (if not already called)
the close frame is queued (if not already sent or queued)
the on success or failure of close frame send, the connection is disconnected. (there is no wait for the remote close frame in this exceptional case)
Failures during handshake are ...
On a WebSocket Client the connect will fail with an exception (this could be reported as a failure when attempting to get the Session object from the connect future)
On a WebSocket Server the connect will not succeed, no WebSocket Session is created, no Endpoint is created, no onOpen() is called.

ItemViewModel: method code is too large

I have a database table with 270 columns I need to work with. I wrote some code generators to help me keep my sanity, but I have an issue with ItemViewModel class - it refuses to compile with 'Method code too large' exception.
The class is plain:
class F321PModel: ItemViewModel<F321P>() {
val id = bind(F321P::idProperty)
// 269 more lines below
I receive method too large exception even for 50 columns. Is bind introduces so huge overhead ? I don't think that 50 columns table is something extreme, maybe it is possible to optimize something ?
Here is problem classes https://gist.github.com/anonymous/d0978899ad569839797b025ad081bbf7
Error:Kotlin: [Internal Error] java.lang.RuntimeException: Error generating class file ru/abinet/blt/updateapplication/models/F321PModel.class (compiled from [C:\Users\hachatryan\IdeaProjects\updateapplication\src\main\kotlin\ru\abinet\blt\updateapplication\models\321PModel.kt]): Method code too large!
at org.jetbrains.kotlin.codegen.ClassFileFactory$OutputClassFile.asByteArray(ClassFileFactory.java:255)
at org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt.writeAll(outputUtils.kt:32)
at org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt.writeAll(outputUtils.kt:42)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.writeOutput(KotlinToJVMBytecodeCompiler.kt:98)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.access$writeOutput(KotlinToJVMBytecodeCompiler.kt:67)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$createOutputFilesFlushingCallbackIfPossible$1.invoke(KotlinToJVMBytecodeCompiler.kt:107)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$createOutputFilesFlushingCallbackIfPossible$1.invoke(KotlinToJVMBytecodeCompiler.kt:67)
at org.jetbrains.kotlin.codegen.state.GenerationStateKt$GenerationStateEventCallback$1.invoke(GenerationState.kt:259)
at org.jetbrains.kotlin.codegen.state.GenerationStateKt$GenerationStateEventCallback$1.invoke(GenerationState.kt:258)
at org.jetbrains.kotlin.codegen.state.GenerationState.afterIndependentPart(GenerationState.kt:215)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:67)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.generatePackage(KotlinCodegenFacade.java:100)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.doGenerateFiles(KotlinCodegenFacade.java:78)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:45)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:450)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:152)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:158)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:61)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:107)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$1.invoke(CompileServiceImpl.kt:380)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$1.invoke(CompileServiceImpl.kt:96)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:892)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:96)
at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:919)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:891)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:378)
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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Method code too large!
at org.jetbrains.org.objectweb.asm.MethodWriter.getSize(MethodWriter.java:2036)
at org.jetbrains.org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:850)
at org.jetbrains.kotlin.codegen.ClassBuilderFactories$2.asBytes(ClassBuilderFactories.java:126)
at org.jetbrains.kotlin.codegen.DelegatingClassBuilderFactory.asBytes(DelegatingClassBuilderFactory.kt:36)
at org.jetbrains.kotlin.codegen.DelegatingClassBuilderFactory.asBytes(DelegatingClassBuilderFactory.kt:36)
at org.jetbrains.kotlin.codegen.DelegatingClassBuilderFactory.asBytes(DelegatingClassBuilderFactory.kt:36)
at org.jetbrains.kotlin.codegen.ClassFileFactory$ClassBuilderAndSourceFileList.asBytes(ClassFileFactory.java:287)
at org.jetbrains.kotlin.codegen.ClassFileFactory$OutputClassFile.asByteArray(ClassFileFactory.java:252)
... 45 more
I've come across this same error with ~60 properties, I managed to get around it by wrapping each bind call in a lazy delegate:
val id: LongProperty by lazy<LongProperty> {
bind(F321P::idProperty)
}

Ignite event listener registration error

I am trying to implement a remote listener on Apache ignite, but for some reason the registration seems to be failing, use the following code.
IgniteMessaging message = ignite.message(ignite.cluster());
message.remoteListen("topic1", new IgniteBiPredicate<UUID, String>() {
#Override
public boolean apply(UUID e1, String e2) {
System.out.println("message received" + e2);
return true;
}
});
But I get the following error during registration.
Exception in thread "main" class org.apache.ignite.spi.IgniteSpiException: Failed to marshal custom event: StartRoutineDiscoveryMessage [startReqData=StartRequestData [prjPred=AlwaysTruePredicate [], clsName=null, depInfo=null, hnd=GridMessageListenHandler [pred=independent.messaging.Receiver$1#e24ddd0, clsName=null, depInfo=null, depEnabled=false], bufSize=1, interval=0, autoUnsubscribe=false], keepBinary=false, routineId=13f09f06-4ebe-4cc8-9671-54162472df15]
at org.apache.ignite.spi.discovery.tcp.ServerImpl.sendCustomEvent(ServerImpl.java:773)
at org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi.sendCustomEvent(TcpDiscoverySpi.java:453)
at org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.sendCustomEvent(GridDiscoveryManager.java:2090)
at org.apache.ignite.internal.processors.continuous.GridContinuousProcessor.startRoutine(GridContinuousProcessor.java:748)
at org.apache.ignite.internal.IgniteMessagingImpl.remoteListen(IgniteMessagingImpl.java:212)
at independent.messaging.Receiver.listenForMessages(Receiver.java:71)
at independent.messaging.Receiver.main(Receiver.java:55)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to serialize object: StartRoutineDiscoveryMessage [startReqData=StartRequestData [prjPred=AlwaysTruePredicate [], clsName=null, depInfo=null, hnd=GridMessageListenHandler [pred=independent.messaging.Receiver$1#e24ddd0, clsName=null, depInfo=null, depEnabled=false], bufSize=1, interval=0, autoUnsubscribe=false], keepBinary=false, routineId=13f09f06-4ebe-4cc8-9671-54162472df15]
at org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal0(JdkMarshaller.java:85)
at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.marshal(AbstractNodeNameAwareMarshaller.java:70)
at org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal0(JdkMarshaller.java:99)
at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.marshal(AbstractNodeNameAwareMarshaller.java:58)
at org.apache.ignite.internal.util.IgniteUtils.marshal(IgniteUtils.java:9815)
at org.apache.ignite.spi.discovery.tcp.ServerImpl.sendCustomEvent(ServerImpl.java:769)
... 6 more
Caused by: java.io.NotSerializableException: independent.messaging.Receiver
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at org.apache.ignite.internal.GridMessageListenHandler.writeExternal(GridMessageListenHandler.java:244)
at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1459)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1430)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at org.apache.ignite.internal.processors.continuous.StartRequestData.writeExternal(StartRequestData.java:241)
at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1459)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1430)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal0(JdkMarshaller.java:80)
... 11 more
What could be the possible reason for this error?
Your IgniteBiPredicate will be serialized and sent to the other nodes, so, in your case, as this class is anonymous, outer class will be serialized too.
I would recommend creating private static class for predicate with this implementation and creating instance of it as an argument for remoteListen method

JavaFX 2 -- Setting the defaultButton property: mutually exclusive?

In Visual Basic 6, if you set the DefaultButton property of a form button control to true, the same property on all the other button controls in the form was set to false, i.e. the property was mutually exclusive (like a radio button).
I am getting behavior on my GUI that seems to indicate that more than one button in JavaFX may have the defaultButton property set to true, and that more than one button will receive VK_Enter button events from the system.
The JavaFX 2.2 documentation for the setDefaultButton() method and defaultButton property does not clarify this issue.
I have one AnchorPanel with a bunch of controls and another with a separate bunch of controls. These are shown on the same stage, and which one is setVisible(true) to the user depends on what information he's working with.
I'm wondering if I need to iterate through the button controls on my active panes and set the defaultButton property to false for all of them before I try to set one to true in order to avoid odd behavior resulting from more than one button receiving Enter Key events.
EDIT 05/05/2013 -- Here is the ChangeListener code I have. I had originally written it as an anonymous inner class that I was attaching directly to the focusedProperty of the TextField control txtDx. However, I thought that maybe I could fix my error by removing the Listener during those times when I didn't want it firing (i.e., when its pane was invisitble or disabled). So I moved the Listener to an inner class and have an instance of it referenced to by an instance variable. Having the reference allows me to add and remove the Listener depending on which pane is displayed.
Anyway, here is the Listener class:
private class FocusPropertyChangeListener implements ChangeListener<Boolean> {
FocusPropertyChangeListener() { System.out.println("New FPCL instance"); }
#Override
public void changed(ObservableValue<? extends Boolean> ov,
Boolean oldb, Boolean newb) {
System.out.println("Focus change triggered");
if (ancEncEditor.isVisible() && !ancEncEditor.isDisabled()) {
boolean b = (newb != null && newb.booleanValue() == true);
System.out.println("txtDx focus change event triggered: DxAdd = " + b);
btnWindowCommit.setDefaultButton(!b);
btnWindowClose.setCancelButton(true);
btnDxAdd.setDefaultButton(b);
}
}
}
As you can see, in the event handler I make two (presumably concurrent) calls to setDefaultButton. The intent is to use btnDxAdd if I am editing in txtDx, otherwise use btnWindowCommit. I'll try getting rid of the presumably unneeded calls to setDefaultButton and see if I still get ConcurrentModificationExceptions.
EDIT 05/05/2013 -- Adding the stack trace. Here goes...
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:894)
at java.util.HashMap$EntryIterator.next(HashMap.java:934)
at java.util.HashMap$EntryIterator.next(HashMap.java:932)
at com.sun.javafx.collections.ObservableMapWrapper$ObservableEntrySet$1.next(ObservableMapWrapper.java:560)
at com.sun.javafx.collections.ObservableMapWrapper$ObservableEntrySet$1.next(ObservableMapWrapper.java:548)
at com.sun.javafx.scene.KeyboardShortcutsHandler.processAccelerators(KeyboardShortcutsHandler.java:286)
at com.sun.javafx.scene.KeyboardShortcutsHandler.dispatchBubblingEvent(KeyboardShortcutsHandler.java:119)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Scene$KeyHandler.process(Scene.java:3513)
at javafx.scene.Scene$KeyHandler.access$2300(Scene.java:3472)
at javafx.scene.Scene.impl_processKeyEvent(Scene.java:1904)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2270)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:136)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:100)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:163)
at com.sun.glass.ui.View.handleKeyEvent(View.java:518)
at com.sun.glass.ui.View.notifyKey(View.java:951)
at com.sun.glass.ui.win.WinApplication._enterNestedEventLoop(Native Method)
at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:383)
at com.sun.glass.ui.EventLoop.enter(EventLoop.java:83)
at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:520)
at javafx.stage.Stage.showAndWait(Stage.java:397)
at org.kls.md.censusassistant.DialogController.showAndWait(DialogController.java:94)
at org.kls.md.censusassistant.DCMainEditor.handleEncDetails(DCMainEditor.java:287)
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 sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1435)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Node.fireEvent(Node.java:6863)
at javafx.scene.control.Button.fire(Button.java:179)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:193)
at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:336)
at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:329)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:64)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3328)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3168)
at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3123)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1563)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2265)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:250)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:173)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:292)
at com.sun.glass.ui.View.handleMouseEvent(View.java:528)
at com.sun.glass.ui.View.notifyMouse(View.java:922)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
at java.lang.Thread.run(Thread.java:722)
EDIT 05/05/2013 -- I altered my code so that I would no longer be clearing former settings of defaultButton, i.e. just one call to setDefaultButton(true). The idea was that since the backing code performs this operation using a Runnable, -perhaps- this was the cause of the ConcurrentModificationExceptions I was getting.
So, now it does appear that in fact I am no longer able to trigger ConcurrentModificationExceptions in my code when I attempt to change between btnDxAdd and btnWindowCommit as the default button.
However ...
I am also no longer able to get the behavior I want. When I am editing in the txtDx control now, I can press the Enter key all day and the button will not fire. I have confirmed that my focusProperty ChangeListener fired and that a single call to txtDx.setDefaultButton(true) was made. Regardless, I am not able to get the behavior I want.
Bug about javadoc clarification : javafx-jira.kenai.com/browse/RT-30200
Bug about implementation : https://javafx-jira.kenai.com/browse/RT-30206
I watched code from skin class, which is observable from OpenJFX:
What is happening, when you setDefault(true/false):
Runnable defaultButtonRunnable = new Runnable() {
public void run() {
if (!getSkinnable().isDisabled()) {
getSkinnable().fire();
}
}
};
private void setDefaultButton(boolean value) {
KeyCode acceleratorCode = KeyCode.ENTER;
defaultAcceleratorKeyCodeCombination =
new KeyCodeCombination(acceleratorCode);
if (! value) {
/*
** first check of there's a default button already
*/
Runnable oldDefault = getSkinnable().getParent().getScene().getAccelerators().get(defaultAcceleratorKeyCodeCombination);
if (!defaultButtonRunnable.equals(oldDefault)) {
/*
** is it us?
*/
getSkinnable().getParent().getScene().getAccelerators().remove(defaultAcceleratorKeyCodeCombination);
}
}
getSkinnable().getParent().getScene().getAccelerators().put(defaultAcceleratorKeyCodeCombination, defaultButtonRunnable);
}
How it works : when you set new button as default, it finds the existing default button, and removes acelerator on ENTER key press from acelerators list stored at scene. And adds itself as a default button. So you don't need to setDefault on other buttons.

H2 database throwing null pointer exception

I am new to H2 database, I ran into a particular problem where I was running a function named format.
public static String format(Double sumValue,Integer decimalValue){
if(sumValue==null)
return null;
else{
//format in particular order.
}
}
There are chances of sumValue getting null value.
when I am running a query it is throwing a following exception
SELECT format(commamount,2) as formatted FROM pshipcommdetail [90105-153]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
at org.h2.message.DbException.get(DbException.java:156)
at org.h2.message.DbException.convertInvocation(DbException.java:295)
at org.h2.engine.FunctionAlias$JavaMethod.getValue(FunctionAlias.java:405)
at org.h2.expression.JavaFunction.getValue(JavaFunction.java:38)
at org.h2.expression.Alias.getValue(Alias.java:35)
at org.h2.command.dml.Select.queryFlat(Select.java:519)
at org.h2.command.dml.Select.queryWithoutCache(Select.java:614)
at org.h2.command.dml.Query.query(Query.java:269)
at org.h2.command.dml.Query.query(Query.java:239)
at org.h2.command.dml.Query.query(Query.java:37)
at org.h2.command.CommandContainer.query(CommandContainer.java:78)
at org.h2.command.Command.executeQuery(Command.java:181)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:278)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:137)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at reports.functions.Format.format(Format.java:15)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.h2.engine.FunctionAlias$JavaMethod.getValue(FunctionAlias.java:393)
I went through the documentation and was able to figure out that the aruguments should be of wrapper class hence I changed to double!
Can anyone of you please help me to figure out where the actual problem is?
Thanking you
With Regards
Phani Kumar
This question was answered on the H2 mailing list:
http://groups.google.com/group/h2-database/browse_thread/thread/a4105b923d79bf28#
It was a bug in Phani's code.

Resources