The following code snippet doesnt throw any error when executed in a standalone mode. When I deploy this into a web server [implementing a server's interface and added as JAR into classpath], I get
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.nbis.process.JSON_2_File_Split_V004.fn_1_parserEntity(JSON_2_File_Split_V004.java:256)
at com.nbis.process.JSON_2_File_Split_V004.fn_0_primaryCaller(JSON_2_File_Split_V004.java:177)
at com.nbis.process.JSON_2_File_Split_V004.execute(JSON_2_File_Split_V004.java:151)
Code Snippet:
this.callable = new JSON_3_File_Process_V005(this.originalFileName, this.inProgressDirLoc, this.processedDirLoc, "[" + jSONRecord.toString() + "]", this.dataMDHolder, this.dataAccIDValueMap, this.dataCountryNameValueMap);
String[] fullContent = null;
try {
fullContent = executor.submit(this.callable).get();
} catch (ExecutionException e) {
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
log.info("Srii: " + errors.toString());
executor.shutdown();
return 7;
}
Adding the get's return value to an ExecutorCompletionService would be an option, but would that not kill the concept of asynchronous processing? In other words, I collect in StringBuilder the output string from callable get and store to a disk when the get count reaches a specific number. Once data is emitted to disk, I refresh the StringBuilder. This way I push data to a disk at regular intervals without having to keep them in memory.
Any suggestions as to what wrong am I doing here? Appreciate any inputs. Thank you.
This is fixed. If it could useful:
The problem was with the way the variables were declared. I had to declare a class-level variable as static so the any changes applied to this one started reflecting everywhere else. Strangely enough, I dint see the problem when it was executed stand-alone.
EDIT on 13112019: Moving my comment to the answer section, on request:
As its quite long time back, I dont recollect exactly the variable details. But I believe it is one of the following: this.originalFileName, this.inProgressDirLoc, this.processedDirLoc , this.dataMDHolder, this.dataAccIDValueMap, this.dataCountryNameValueMap I had to set them as static as values assigned [or modified] by any of the member was not reflecting during references of the variable within the class.
Similar issue I faced in spring rest project. I was using #Autowired annotation to inject an object inside Callable Thread class.
That object was causing Null Pointer exception sometimes. Then removing the #Autowired annotation and passing that object in constructor while creating callable thread class object fixed my issue.
Related
I could be wrong about which line is causing the problem, but the error changes everytime I change this if() statement:
try {
while(true) {
String LRU = hashOperation();
System.out.println("In worker thread, this should be valid JSON: " + LRU);
if (jsonValidator.isStringValidJSON(LRU) && !LRU.isEmpty()) {
HashMap<String,String> messageMap = jsonGenerator.readJSON(LRU);
So I assume the problem is with this if() statement. If I write it like this:
if (jsonValidator.isStringValidJSON(LRU)) {
Then the app starts up and I get this exception:
In worker thread, this should be valid JSON:
Exception in worker thread in Main::main: No content to map to Object due to end of input
but if I write it like this:
if (jsonValidator.isStringValidJSON(LRU) && !LRU.isEmpty()) {
Then the app starts up, but then almost instantly dies:
/usr/bin/java -cp /home/jenkins/run-nlp/SSAM.jar com.sofar.SSAM.Main
Starting NLP app 2015/08/30 21:42:28
Loading classifier from dependencies/english.all.7class.distsim.crf.ser.gz ... Killed
The basic idea here is that the app starts up and then spins up some background threads that poll endlessly on Redis, looking for input (the input comes from another app, that publishes data to a channel on Redis).
When I see "Killed" I assume that an Exception went uncaught, but I have this whole Thread::run() wrapped in a try/catch that ends with:
} catch (Exception e) {
System.out.println("Exception in worker thread in Main::main: " + e.getMessage());
}
You can see that this is the Exception message that I get if I do this:
if (jsonValidator.isStringValidJSON(LRU)) {
Although it is possible the error is elsewhere, and I think it is odd that an empty string would be valid JSON, I thought I would screen out that possibility with:
if (jsonValidator.isStringValidJSON(LRU) && !LRU.isEmpty()) {
Why would this one change cause my app to be Killed?
UPDATE:
I refactored the app to this:
static void processMessage(ssamBrain ssamBrain, Jedis jedis, HashMap<String, String> responseMap, JsonGenerator jsonGenerator, JSONValidator jsonValidator, String LRU) {
try {
if (!LRU.isEmpty()) {
HashMap<String,String> messageMap = jsonGenerator.readJSON(LRU);
Transformer transformer = new Transformer();
Again, the line that causes the problem seems to be:
if (!LRU.isEmpty()) {
If I don't have that if() statement, then the code gets:
java.io.EOFException: No content to map to Object due to end of input
on the next line, since an empty string is not valid JSON.
But when I add this:
if (!LRU.isEmpty()) {
Then my app dies on startup.
Maybe autoboxing is the problem? Or the absence of it? Assume for now:
LRU = "";
I assume I can call methods on it, but maybe not? And why wouldn't I get an Exception?
It's possible the problem is elsewhere, but that if() statement seems to be the main thing that causes the problem to surface.
UPDATE
UPDATE
The app sometimes survives for a few minutes, but other times it dies after a few seconds. So I guess I need to ask:
1.) when a Java app says "Killed" in the terminal, does that always mean that an Exception went uncaught?
2.) what might cause such variable behavior?
How to works if operator:
if (CONDITION_1 && CONDITION_2){
doSomething();
}
checks CONDITION_1 - if it is true:
checks CONDITION_2 - if it is true:
runs doSometring().
If CONDITION_1 is false or throws an exception, CONDITION_2 never checks.
Please, show the exception stackTrace.
Change:
if (jsonValidator.isStringValidJSON(LRU) && !LRU.isEmpty())
to:
if (!LRU.isEmpty() && jsonValidator.isStringValidJSON(LRU))
So, you first check if LRU is empty and if it is not - you run validation.
I embed jruby script engine into my java program by using javax.script.ScriptEngineManager
I made some jruby code that end with do ~ end block,
after running all code, NullPointerException occured.
but code ends with any other statement, no exception occurs.
version : 1.7.19
Caused by: java.lang.NullPointerException
at org.jruby.embed.variable.Argv.updateARGV(Argv.java:169)
at org.jruby.embed.variable.Argv.retrieve(Argv.java:158)
at org.jruby.embed.variable.VariableInterceptor.retrieve(VariableInterceptor.java:154)
at org.jruby.embed.internal.BiVariableMap.retrieve(BiVariableMap.java:378)
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:124)
in ARGV.java updateARGV
if (vars.containsKey((Object)name)) {
var = vars.getVariable((RubyObject)receiver.getRuntime().getTopSelf(), name);
var.setRubyObject(argv);
vars.getVariable returned null because of isReceiverIdentical return false
in BiVariableMap.java
if (var.isReceiverIdentical(receiver)) {
return var;
}
In isReceiverIdentical, this method just compare receiver with BiVariable's receiver usgin '=='.
Is this jruby bug? Or do I have to do something for this?
If you need more information about this problem, plz comment it!
I got ScriptEngine(engine) from ScriptEngineManager and set some java instance and method like this
engine.put("this", console);
engine.eval("$command = $this.java_method :command, [java.lang.String]");
here is my test ruby code. result and tab is java object
that has some method return String and list.
result = $command.call "something to pass"
puts result.getMessage
tabular = result.getData
tabular.each do |tab|
rows = tab.getRows
rows.each do |row|
puts row
end
puts tab.getColumnNames
end
I had created ruby type object in my java code by creating new Ruby object...
This causes checking fail in updateARGV because a receiver that register variable in BiVariableMap and another receiver that update variable are different.
So, I got a Ruby object from new ScriptingContainer(from it we can always get a same Ruby object if local context is singleton) and used it to create new ruby type object in my java code.
Reference: https://github.com/jruby/jruby/wiki/RedBridge#Singleton
I have used EMC Documentum Foundation Classes to perform some actions in documentum repository. The code was working fine. I exported the project as a runnable JAR and then tried to run it. However I got following error and I am not able to understand it.
And here is the code for DocMovementHandler.getSession()
Actually this is no new code but regular code for obtaining documentum session
public IDfSession getSession(String userName, String password)
{
DfClientX clientx = null;
IDfClient client = null;
IDfSession session = null;
try {
// create a client object using a factory method in DfClientX
clientx = new DfClientX();
client = clientx.getLocalClient(); //takes time
// call a factory method to create the session manager
IDfSessionManager sessionMgr = client.newSessionManager();
// create an IDfLoginInfo object and set its fields
IDfLoginInfo loginInfo = clientx.getLoginInfo();
loginInfo.setUser(userName);
loginInfo.setPassword(password);
// set single identity for all docbases
sessionMgr.setIdentity("xyz_repo", loginInfo);
session = sessionMgr.getSession("xyz_repo"); //takes time
//sessionMgr.beginTransaction();
System.out.println("Session obtaied.");
}
catch (DfServiceException dse)
{
DfLogger.debug(this, "Error while beginning transaction. ", null, dse);
dse.printStackTrace();
}
catch (Exception e)
{
DfLogger.debug(this, "Error while creating a new session. ", null, e);
e.printStackTrace();
}
return session;
}
And that line 38 is client = clientx.getLocalClient();
InvocationTargetException is a wrapper. It says, "an exception occurred behind this reflection call", and you use getCause() to get at the inner exception.
The stack trace contains the inner exception. It's an ExceptionInInitializerError. That's another wrapper. It says, "whatever you did caused a new class to be loaded, and that class's static initializer threw an exception".
The final exception in this chain is the NullPointerException. That's the one you need to solve. Which means you need to debug this com.documentum thing. As the comments pointed out, that's not going to be easy.
Here is the most likely problem:
The static initializer in one of the classes whose names you have struck is adding an entry with either a null key or a null value to a Hashtable, which does not allow null keys or values.
It is using the Hashtable as a place to store a bunch of persistent properties and all that, and my guess is that the value for one of the entries was the null (which is a perfectly reasonable way to indicate that some feature is unavailable or something like that).
The now deprecated Hashtable needs to be replaced with the more modern HashMap.
If it is a library, that you can't just modify, you should replace the whole library with an updated version.
Here are some clues may be helpful.
The NullPointerException is thrown by Hashtable#put, and this is normally because either the key or the value is null.
Hashtable#put is called by PreferenceManager.readPersistenceProperties, so most likely it's because something is missing in a properties file so the value is null.
This NPE caused the DfClient class could not be loaded.
DfPreferences is the class loading the DFC configuration file dfc.properties. There must be something wrong with it.
Ohkay I did not pin pointed the root cause, but found the solution that will definitely work everytime.
EMC provides a flavor of Eclipse called Documentum Composer to work with Documentum Projects. Since Eclipse variation we can create other types of projects like normal Java project, dynamic web project, web services in this. So I recreated my project in Documetnum Composer and exported it as JAR and whoaaaa it worked.
I tried this many times and this worked all time.
Some points to note:
You have to replace dfc.properties file in Composer installation folder with one in Content Server
The Export to JAR wizard in Composer is a bit different than one in Eclipse
This is usually caused by dfc.properties being incorrect.
Preferences are stored on the global registry repository and the connection details should be specified in dfc.properties. If not, this (or a similar error can occur).
Also, always try to clear cache and use the correct version of the dfc jar's (v6.7 content server requires 6.7 jars, etc...).
I'm using (or trying to use) Esper to retrieve a specific class of object of which one of the methods returns a specific value. Here's the statement I'm setting now.
EsperEventConsumer consumer = new EsperEventConsumer();
consumer.setEsperStatement("select * from com.my.package.MyClass as test where test.getObject().getValue()='" + myValue + "'");
I know everything else works because when I do the following, everything works fine, except for the lack of filtering that is.
EsperEventConsumer consumer = new EsperEventConsumer();
consumer.setEsperStatement("select * from com.my.package.MyClass");
The statement is specifically thrown on "test.getObject()."
Caused by: com.espertech.esper.client.EPStatementException: Failed to solve 'getObject' to either an date-time or enumeration method, an event property or a method on the event underlying object [select * from com.my.package.MyClass as test where test.getObject().getValue()='dfe28df9-4f8e-4016-907d-d1852f6add49']
Thanks!
Sounds like MyClass doesn't have a method "getObject", provide the full code if still having trouble.
We are getting a mustache play error in production (amazon linux EC2 AMI) but not in development (MACs) and we have tried upgrading the jvm, using the jdk instead, and changing from a tomcat deploy model to match our development environments as much as possible but nothing is working. Please any help would be greatly appreciated. We have lots of shared code in java and javascript using mustache and it would be a big deal to rewrite everything if we had to ditch mustache on the java side.
20:48:52,403 ERROR ~
#6al2dd0po
Internal Server Error (500) for request GET /mystuff/people
Execution exception (In {module:mustache-0.2}/app/play/modules/mustache/MustacheTags.java around line 32)
NullPointerException occured : null
play.exceptions.JavaExecutionException
at play.templates.BaseTemplate.throwException(BaseTemplate.java:90)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:257)
at play.templates.Template.render(Template.java:26)
at play.templates.GroovyTemplate.render(GroovyTemplate.java:187)
at play.mvc.results.RenderTemplate.<init>(RenderTemplate.java:24)
at play.mvc.Controller.renderTemplate(Controller.java:660)
at play.mvc.Controller.renderTemplate(Controller.java:640)
at play.mvc.Controller.render(Controller.java:695)
at controllers.MyStuff.people(MyStuff.java:183)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException
at play.modules.mustache.MustacheTags._template(MustacheTags.java:32)
at play.modules.mustache.MustacheTags$_template.call(Unknown Source)
at /app/views/User/people.html.(line:22)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:232)
... 13 more
Seems the issue is with the threadlocal. In Prod as per my logs, the session gets initialized with the main thread.
[2012-06-30 18:35:38,102] INFO 10097[**main**] - Mustache module initialized
However, MustacheTag tries to access with various thread like this during request.
[2012-06-30 17:48:44,669] INFO 66048[**play-thread-1**] - [{module:mustache-0.2}/app/play/modules/mustache/MustacheTags.java:46] _meta() :: MustachePlugin.session():null
So I changed the implementation of MustachePlugin like this.Changed line commented out:
//private static ThreadLocal<MustacheSession> session_ = new ThreadLocal<MustacheSession>();
private static MustacheSession _session = null;
public static MustacheSession session(){
//return session_.get();
return _session;
}
public void onConfigurationRead(){
// some code
_session = new MustacheSession(compiler, root);
// some code
}
And it is working fine now in prod mode! I see no reason why it should have been in a ThreadLocal in the first place as the session gets initialized at startup!
your issue is difficult to reproduce so i'll give few pointers here. you have tried to eliminate of issue being env issue. so other possible issues could be
data issue: many times reason for production issue is usually difference in actual data and test data. check if its data issue which is casuing NPE.
code issue: Is there something at people.html.(line:22) causing issue. first try removing / altering that to check if thats causing issue. Or can you get source code of mustache (exact version which you are using) and see what object its trying to create and where its failing.
Properties file for different environments: do you have different proprties file for each env? If yes, have u missed on any property for prod env?
You have a NullPointerException on MustacheTags.java at line 32.
This means that you are probably calling a method of the Mustache library and passing a null value.
Try logging all the parameters you transfer to this method (MyStuff.java line 183?).
You can look at the source code of MustacheTags here, it might help you understand what values you are passing and what should be passed.