View Full Version : Using Quercus standalone: NPE upon any log message

08-04-2010, 12:44 PM
I am currently using Quercus using independently of Rasin.

This is the code I use to setup Quercus:

Quercus quercus = new Quercus();
quercus.setPwd(new FilePath(this.workdir.getAbsolutePath()));

Then I parse/compile the php-script:

compiled = quercus.parse(path);

File stdout = File.createTempFile("php-stdout", null);
WriteStream out = new WriteStream(new FilePath(stdout.getAbsolutePath()).openWriteImpl() );

Env env = quercus.createEnv(compiled, out, null, null);

catch (QuercusDieException exc)
// okay!
catch (QuercusExitException exc)
// okay!
catch (Exception exc)


So far so good.

Now when (for example) I make a typo in the php-code, like typing $ii instead of $i, I get a nasty NPE:

at com.caucho.quercus.env.LongValue.toStringBuilder(L ongValue.java:239)
at com.caucho.quercus.env.Value.toStringValue(Value.j ava:982)
at com.caucho.quercus.env.Value.toStringValue(Value.j ava:974)
at com.caucho.quercus.module.IniDefinition.getAsStrin gValue(IniDefinition.java:258)
at com.caucho.quercus.env.Env.getIni(Env.java:1772)
at com.caucho.quercus.env.Env.getErrorMask(Env.java:6 208)
at com.caucho.quercus.env.Env.error(Env.java:6324)
at com.caucho.quercus.env.Env.error(Env.java:6306)
at com.caucho.quercus.env.Env.notice(Env.java:6149)
at com.caucho.quercus.env.Env.getGlobalEnvVar(Env.jav a:2083)

The root cause is that the env.getErrorMask() looks up a value in INI that it can't find. So I thought that calling env.setErrorMask(0) should take care of that, but that too, calls env.getErrorMask() under the hood, resulting in the same NPE.

The fix was calling this, before running any scripts.

quercus.setIni("error_reporting", "0");

Maybe that could be set by default? It would have saved me from pulling my hear out.

With kind regards,
- Riven