0

I take a ByteArrayInputStream and using Stringbuilder create a full string (sb).

I then take the sb and move it to a String field, which I then try to split on newline is indicated in this post: Split Java String by New Line

I'm getting an error though on the

 String configLines[] = tempL.split("\\r?\\n");

line as follows:

depends on configLines is neither defined in the script nor in dependencies."

This is the only place in the code configLines is mentioned (so far). Any ideas what is wrong with this single line of code? It should just work shouldn't it?

When I comment out this line the code works, when I uncomment it - it fails.

I've seen the byte code and the bytes are 13, 10 for newline, carriage return.

What am I doing wrong? Thanks in advance.

ByteArrayInputStream str = new ByteArrayInputStream(documentData);
StringBuilder sb = new StringBuilder();

int ch;
while((ch = str.read()) != -1) {
    sb.append(Character.toUpperCase((char) ch));
}
if(debug){dI++; logger.severe(dI+thisTrace+"sb: "+sb.toString());}

 String tempL = sb.toString();
 if(debug){dI++; logger.severe(dI+thisTrace+"tempL: "+tempL);}

 String configLines[] = tempL.split("\\r?\\n");

The full error message is as follows, and it's coming from a groovy interpreter, which is also java.

2015-04-11 19:17:39 org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork 
SEVERE: THREAD_ID=377 | HOSTNAME=Mainframe | TENANT_ID=1 | org.bonitasoft.engine.expression.exception.SExpressionEvaluationException : "PROCESS_DEFINITION_ID=7620684800960500232 | PROCESS_NAME=Configure |     PROCESS_VERSION=3.0 | PROCESS_INSTANCE_ID=18001 | ROOT_PROCESS_INSTANCE_ID=18001  | FLOW_NODE_DEFINITION_ID=-7446352707110997787 | FLOW_NODE_INSTANCE_ID=360005 |     FLOW_NODE_NAME=prepareChosenConfigFile | CONNECTOR_DEFINITION_IMPLEMENTATION_CLASS_NAME=prepareChosenConfigFile | CONNECTOR_INSTANCE_ID=340004 | Expression prepareChosenConfigFile with content = </**

This is a print out of the code module as above.

*/> depends on lines is neither defined in the script nor in dependencies."

org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: PROCESS_DEFINITION_ID=7620684800960500232 | PROCESS_NAME=Configure | PROCESS_VERSION=3.0 | PROCESS_INSTANCE_ID=18001 | ROOT_PROCESS_INSTANCE_ID=18001 | FLOW_NODE_DEFINITION_ID=-7446352707110997787 | FLOW_NODE_INSTANCE_ID=360005 | FLOW_NODE_NAME=prepareChosenConfigFile | CONNECTOR_DEFINITION_IMPLEMENTATION_CLASS_NAME=prepareChosenConfigFile | CONNECTOR_INSTANCE_ID=340004 | Expression prepareChosenConfigFile with content = </**

This is a print out of the code module as above.

*/> depends on lines is neither defined in the script nor in dependencies."
at     org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:151)
at org.bonitasoft.engine.expression.impl.ExpressionServiceImpl.evaluate(ExpressionServiceImpl.java:86)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionWithResolvedDependencies(ExpressionResolverServiceImpl.java:215)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionsFlatten(ExpressionResolverServiceImpl.java:120)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluate(ExpressionResolverServiceImpl.java:83)
at org.bonitasoft.engine.core.connector.impl.ConnectorServiceImpl.evaluateInputParameters(ConnectorServiceImpl.java:352)
at org.bonitasoft.engine.connector.ConnectorServiceDecorator.evaluateInputParameters(ConnectorServiceDecorator.java:99)
at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateParameterAndGetConnectorInstance.call(ExecuteConnectorWork.java:198)
at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateParameterAndGetConnectorInstance.call(ExecuteConnectorWork.java:162)
at org.bonitasoft.engine.transaction.JTATransactionServiceImpl.executeInTransaction(JTATransactionServiceImpl.java:288)
at org.bonitasoft.engine.execution.work.ExecuteConnectorWork.work(ExecuteConnectorWork.java:122)
at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42)
at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42)
at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42)
at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42)
at org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork.work(FailureHandlingBonitaWork.java:66)
at org.bonitasoft.engine.work.BonitaWork.run(BonitaWork.java:56)
at org.bonitasoft.engine.work.SequenceRunnableExecutor.innerRun(SequenceRunnableExecutor.java:47)
at org.bonitasoft.engine.work.BonitaRunnable.run(BonitaRunnable.java:35)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: groovy.lang.MissingPropertyException: No such property: lines for class: BScript8
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
at BScript8.run(BScript8.groovy:197)
at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:145)
... 21 more
Community
  • 1
  • 1
Sean
  • 271
  • 1
  • 8
  • 20
  • 4
    It looks like you've posted *half* an error message. Please post the *full* error message... and also, I would *strongly* recommend that you use an `InputStreamReader` instead of your current approach for converting binary data to text. – Jon Skeet Apr 11 '15 at 16:53
  • 1
    you don't need to escape `\r` and `\n`. simply use `split("\r?\n")` – Braj Apr 11 '15 at 17:02
  • @Jon Skeet, thanks, I knew what I was posting. The interpreter in this case gave no other useful information and printed out the full source code. That being said, I've marked your post up because you are right, not the full message was given. Braj, marked up also have removed the unnecessary escape. I've added my solution (well one that works) below. – Sean Apr 12 '15 at 04:29
  • "The interpreter" - what interpreter? You still haven't included the full message - are you saying it wasn't printed? – Jon Skeet Apr 12 '15 at 06:25

1 Answers1

0

Thanks guys, in the end I researched Google for more help. I was astonished to find many sites using what I had used:

String configLines[] = tempL.split("\\r?\\n");

which I believe should work, and still do... :)

However I did find another implementation of the split command as follows:

String[]  configLines = tempL.split("\\r?\\n");

which upon testing did work.

So while I'm happy now that my code is working and I can proceed, can someone enlighten me as to why the former did not work in this case, but the latter does?

The sites which lead me to this answer are as follows:

http://javarevisited.blogspot.com/2011/09/string-split-example-in-java-tutorial.html http://www.java-examples.com/java-string-split-example

Many thanks to all, regards

Sean
  • 271
  • 1
  • 8
  • 20
  • Both should work, although the latter is preferred. I suspect the problem is somewhere else, but we don't have enough information about the context to help you. A short but *complete* program demonstrating the problem, along with more information about how you're compiling and trying to run the code would help. – Jon Skeet Apr 12 '15 at 06:26