Error receiving connection: java.net.SocketException: Invalid argument
Exception in thread "Thread-698" java.lang.RuntimeException: Did not
establish input/output at
Handin2.ConnectionHandlerImpl.run(ConnectionHandlerImpl.java:124) at
java.lang.Thread.run(Thread.java:722)
I have been searching a lot on this exception. Everywhere it seems to be the conclusion that if you compile with the JVM option -Djava.net.preferIPv4Stack=true it will solve the problem. It doesn't for me though. I am running IntelliJ and trying to implement a Chord system with Sockets and Threads. This is where the above mentioned exception is caught and thrown:
if(this.remote == null || this.node == null) {
throw new RuntimeException("Connection handler has not been properly "
+ "initalialized");
}
try{
if(this.out == null) {
this.out = new ObjectOutputStream(remote.getOutputStream());
}
if(this.in == null) {
this.in = new ObjectInputStream(remote.getInputStream());
}
} catch(IOException e) {
System.out.println("Trying to make input/output for remote " + remote);
System.err.println(node.getKey()/Constants.NORMALIZE_KEY+": Error receiving connection: " + e.toString());
return false;
}
I don't know if more code snippets are needed in order to help, but I am simply lost on this exception since the solutions when searching are not helping at all.
Any hints on what triggers this error? The socket exception is caught by the given try-catch block as a special case of an IO exception
if you compile with the JVM option -Djava.net.preferIPv4Stack=true it will solve the problem.
No. If you execute with that JVM option. Nothing to do with the compiler.
Related
Is there a way to restart stack trace given a caught exception? Problem is that when I await a future and it fails, stack trace does not tell which await failed.
For example, stack trace tells that doSomethingMayFail failed:
def doSomethingMayFail() = Future { throw new RuntimeException("test") }
Await.result(doSomethingMayFail(), 1.seconds)
Await.result(doSomethingMayFail(), 1.seconds)
java.lang.RuntimeException: test
at RandomSpec$$anon$7.$anonfun$doSomethingThatFails$1(RandomSpec.scala:79)
at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:672)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:431)
at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
One way to is to catch, fillInStackTrace and rethrow the exception.
try {
Await.result(doSomethingThatFails(), 1.seconds)
} catch {
e => throw e.fillInStackTrace()
}
I am getting the below error when trying to download file in liferay
05:03:35,867 ERROR [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'][PortletRequestDispatcherImpl:115] org.springframework.web.util.NestedServletException: View rendering failed; nested exception is java.lang.IllegalStateException: Cannot obtain Writer because OutputStream is already in use
org.springframework.web.util.NestedServletException: View rendering failed; nested exception is java.lang.IllegalStateException: Cannot obtain Writer because OutputStream is already in use
at org.springframework.web.servlet.ViewRendererServlet.processRequest(ViewRendererServlet.java:96)
at org.springframework.web.servlet.ViewRendererServlet.doGet(ViewRendererServlet.java:67)
Caused by: java.lang.IllegalStateException: Cannot obtain Writer because OutputStream is already in use
at com.liferay.portlet.MimeResponseImpl.getWriter(MimeResponseImpl.java:90)
at com.liferay.portlet.PortletServletResponse.getWriter(PortletServletResponse.java:207)
at com.netcracker.portal.framework.spring.templates.view.SoyDataView.renderMergedOutputModel(SoyDataView.java:93)
and below is the code, i tried searching online but none of them have worked
String defaultFileName = "hello.pdf";
resourceResponse.setContentType("application/octet-stream");
resourceResponse.addProperty(GenericServiceTransport.CONTENT_DISPOSITION, "attachment; filename= hello.pdf" );
resourceResponse.flushBuffer();
try {
out = resourceResponse.getPortletOutputStream();
out.write(backendFile.getContent());
out.flush();
out.close();
} catch (IOException e) {
logger.error(e.getMessage());
}
return;
As first item I'd try to remove the flushBuffer call. You probably get the exception in the line following it, and flushing the buffer surely will use the output stream.
If that doesn't help, please add mute code, e.g. the complete method including its signature
I'm using logback 1.7.5 with play framework 2.2.4, during working I'm getting such error:
Exception in thread "Thread-5" java.lang.ExceptionInInitializerError
at controllers.db.SyncDBManager.createDeviceCollectionsIfNotExists(SyncDBManager.scala)
at server.impl.logic.controller.DeviceInitializer.checkAuthenticationResponse(DeviceInitializer.java:226)
at server.impl.logic.controller.DeviceInitializer.processReceivedFrames(DeviceInitializer.java:117)
at server.impl.logic.controller.DeviceController.onReceivedPackets(DeviceController.java:77)
at server.impl.logic.io.DeviceReader.run(DeviceReader.java:130)
Caused by: java.util.NoSuchElementException: None.get
at scala.None$.get(Option.scala:313)
at scala.None$.get(Option.scala:311)
at controllers.base.MongoSyncHelper$class.$init$(MongoSyncHelper.scala:16)
at controllers.db.SyncDBManager$.<init>(SyncDBManager.scala:32)
at controllers.db.SyncDBManager$.<clinit>(SyncDBManager.scala)
... 5 more
But only on console, how can I catch such exception and write it to file?
Seems like an ordinary stack trace in a console printed with the sysout. Depending on your design if you want to log an exception with the Play logger you should do it in a catch block with one of logger's methods by passing an exception as one of parameters. For example:
try {
// code
} catch {
case e: Exception => play.api.Logger.error("An error occurred", e)
}
The logger level is up to you. If you don't have a catch block and want to log an unexpected exception that occurs in any place of an application you should log it in the Global object by overriding onError method.
override def onError(request: RequestHeader, e: Throwable): Future[SimpleResult] = {
play.api.Logger.error("An error occurred", e)
super.onError(request, e)
}
Remember that onError method is called only in the production mode.
I am trying to login Facebook by using multiple sets of login cridential from external excel sheet using TestNG but in between the code what i have written throws:
FAILED: f
java.lang.NullPointerException
at DataDriven.loginRetesting.f(loginRetesting.java:31)
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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Code:
#Test
public void f() throws Exception{
FileInputStream fi=new FileInputStream("E:\\workspace99\\SeleniumAutomations\\testdata\\LoginData.xls");
Workbook w=Workbook.getWorkbook(fi);
Sheet s=w.getSheet(0);
for (int i = 1; i < 8; i++) {
driver.findElement(By.id("email")).sendKeys(s.getCell(0,i).getContents());
driver.findElement(By.id("pass")).sendKeys(s.getCell(1,i).getContents());
driver.findElement(By.id("u_0_1")).click();
Thread.sleep(1000);
if (selenium.isElementPresent("id=userNavigationLabel")) {
//driver.findElement(By.cssSelector("span.gb_V.gbii")).click();
driver.findElement(By.id("userNavigationLabel")).click();
driver.findElement(By.cssSelector("input.uiLinkButtonInput")).click();
Thread.sleep(1000);
}
else{
System.out.println("invalid cridential");
driver.findElement(By.id("email")).clear();
driver.findElement(By.id("pass")).clear();
}
}
}
I am not able to find out where the problem is? so how to solve it.
For one thing, don't use "throws Exception" in the method declaration. Instead, have a try block inside the method with a "not null assertion".
Keep in mind that you never want to throw typical exceptions in a test method because it will drop you out of the test lifecycle too early and skip your #After phases. An exception thrown in a #Before annotated method will probably cause a SkipAssertion.
So, what you want to do instead is fail assertions. So, if you have a exception condition that occurs sometimes, swallow the exception (don't throw it) and use an assertion to handle it.
For example:
try {
} catch ( NullPointerException e ) {
Assert.assertTrue( "There was an error in blah.", false );
}
Null pointer means, exepected value of variable is null.
Please check the file exists at the specified path "E:\workspace99\SeleniumAutomations\testdata\LoginData.xls" and you get the value correctly from the file.
The stack trace says the issue is line 31 in your code but your snippet does not allow us to work out where line 31 is .
you are calling "selenium.isElementPresent". Could "selenium" be nil?
We are using tools.nsc.interpreter.IMain's bind() and interpret() method to execute scala scripts on a server. This is on on scala 2.9.1 and Java 7u2.
After repeatedly using the same IMain instance, the bind() methods suddenly starts to take very long time (5-6 seconds and even longer). I have tried close() reset() but nothing helps. Weird thing is that the sudden slowness occurs after several uses.
Code snippet (that is executed over and over again):
main.bind("status", status)
try {
main.interpret(prepare(restriction, input))
} catch {
case e: Exception =>
status.setCode("ERR6")
status.setSummary("Error Interpreting Restriction")
status.setType(MetaFileElements.ERROR_VALUE)
status.setValue("Restriction: \"" + restriction + "\", Input: \"" + input + "\"")
}
Another Issue is evetually the process crashes with this error:
Exception in thread "main" java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1061)
at java.lang.ClassLoader.loadClass(ClassLoader.java:412)
at java.lang.ClassLoader.loadClass(ClassLoader.java:410)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at scala.tools.nsc.util.Exceptional$.unwrap(Exceptional.scala:140)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$handleException$1$1.apply(IMain.scala:821)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$handleException$1$1.apply(IMain.scala:818)
at scala.tools.nsc.interpreter.IMain$$anonfun$withoutBindingLastException$2.apply(IMain.scala:228)
at scala.util.control.Exception$Catch.apply(Exception.scala:88)
at scala.tools.nsc.interpreter.IMain.withoutBindingLastException(IMain.scala:226)
at scala.tools.nsc.interpreter.IMain$Request.handleException$1(IMain.scala:818)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:838)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:471)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:503)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:468)
at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:525)
at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:544)
at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:545)
at com.nomura.fi.spg.kozo.meta.client.helper.RestrictionsHelper$.execute(RestrictionsHelper.scala:22)