Where is the Chinese character "𩄀" in a java .class file - java

I have such a java class:
public class UnicodeTest {
public static void main(String[] args) {
String s = "中";
String s1 = "𩄀";
System.out.println(s.length());
System.out.println(s1.length());
System.out.println(s1.toCharArray().length);
}
}
then I use xxd to see the compiled class file:
0000000: cafe babe 0000 0032 0031 0700 0201 000b .......2.1......
0000010: 556e 6963 6f64 6554 6573 7407 0004 0100 UnicodeTest.....
0000020: 106a 6176 612f 6c61 6e67 2f4f 626a 6563 .java/lang/Objec
0000030: 7401 0006 3c69 6e69 743e 0100 0328 2956 t...<init>...()V
0000040: 0100 0443 6f64 650a 0003 0009 0c00 0500 ...Code.........
0000050: 0601 000f 4c69 6e65 4e75 6d62 6572 5461 ....LineNumberTa
0000060: 626c 6501 0012 4c6f 6361 6c56 6172 6961 ble...LocalVaria
0000070: 626c 6554 6162 6c65 0100 0474 6869 7301 bleTable...this.
0000080: 000d 4c55 6e69 636f 6465 5465 7374 3b01 ..LUnicodeTest;.
0000090: 0004 6d61 696e 0100 1628 5b4c 6a61 7661 ..main...([Ljava
00000a0: 2f6c 616e 672f 5374 7269 6e67 3b29 5608 /lang/String;)V.
00000b0: 0011 0100 03e4 b8ad 0800 1301 0006 eda1 ................
00000c0: a4ed b480 0900 1500 1707 0016 0100 106a ...............j
00000d0: 6176 612f 6c61 6e67 2f53 7973 7465 6d0c ava/lang/System.
00000e0: 0018 0019 0100 036f 7574 0100 154c 6a61 .......out...Lja
00000f0: 7661 2f69 6f2f 5072 696e 7453 7472 6561 va/io/PrintStrea
0000100: 6d3b 0a00 1b00 1d07 001c 0100 106a 6176 m;...........jav
0000110: 612f 6c61 6e67 2f53 7472 696e 670c 001e a/lang/String...
0000120: 001f 0100 066c 656e 6774 6801 0003 2829 .....length...()
0000130: 490a 0021 0023 0700 2201 0013 6a61 7661 I..!.#.."...java
0000140: 2f69 6f2f 5072 696e 7453 7472 6561 6d0c /io/PrintStream.
0000150: 0024 0025 0100 0770 7269 6e74 6c6e 0100 .$.%...println..
0000160: 0428 4929 560a 001b 0027 0c00 2800 2901 .(I)V....'..(.).
0000170: 000b 746f 4368 6172 4172 7261 7901 0004 ..toCharArray...
0000180: 2829 5b43 0100 0461 7267 7301 0013 5b4c ()[C...args...[L
0000190: 6a61 7661 2f6c 616e 672f 5374 7269 6e67 java/lang/String
00001a0: 3b01 0001 7301 0012 4c6a 6176 612f 6c61 ;...s...Ljava/la
00001b0: 6e67 2f53 7472 696e 673b 0100 0273 3101 ng/String;...s1.
00001c0: 000a 536f 7572 6365 4669 6c65 0100 1055 ..SourceFile...U
00001d0: 6e69 636f 6465 5465 7374 2e6a 6176 6100 nicodeTest.java.
00001e0: 2100 0100 0300 0000 0000 0200 0100 0500 !...............
00001f0: 0600 0100 0700 0000 2f00 0100 0100 0000 ......../.......
0000200: 052a b700 08b1 0000 0002 000a 0000 0006 .*..............
0000210: 0001 0000 0002 000b 0000 000c 0001 0000 ................
0000220: 0005 000c 000d 0000 0009 000e 000f 0001 ................
0000230: 0007 0000 0078 0002 0003 0000 0026 1210 .....x.......&..
0000240: 4c12 124d b200 142b b600 1ab6 0020 b200 L..M...+..... ..
0000250: 142c b600 1ab6 0020 b200 142c b600 26be .,..... ...,..&.
0000260: b600 20b1 0000 0002 000a 0000 001a 0006 .. .............
0000270: 0000 0005 0003 0006 0006 0007 0010 0008 ................
0000280: 001a 0009 0025 000a 000b 0000 0020 0003 .....%....... ..
0000290: 0000 0026 002a 002b 0000 0003 0023 002c ...&.*.+.....#.,
00002a0: 002d 0001 0006 0020 002e 002d 0002 0001 .-..... ...-....
00002b0: 002f 0000 0002 0030 ./.....0
I have found the Chinese character "中" in line 12 03e4 b8ad, unicode U+4E2D, which in UTF-8 is E4 B8 AD, but I can't find another character "𩄀", unicode U+29100, which I expected something like "04 F0 A9 84 80", why?

Let's use javap.
Compile first with
javac UnicodeTest.java
Then disassemble with
javap -v UnicodeTest.class (truncated to relevant part) :
Constant pool:
#1 = Methodref #9.#18 // java/lang/Object."<init>":()V
#2 = String #19 // 中
#3 = String #20 // 𩄀
#4 = Fieldref #21.#22 //
... truncated
#17 = Utf8 UnicodeTest.java
#18 = NameAndType #10:#11 // "<init>":()V
#19 = Utf8 中
#20 = Utf8 𩄀
Item #20 in constant pool is what you are looking for.
Now, you let's check JVM class file format.
Utf8 datastructure is CONSTANT_Utf8_info
CONSTANT_Utf8_info {
u1 tag;
u2 length;
u1 bytes[length];
}
tag is CONSTANT_Utf8 (01). length is 00 06, bytes are ed a1 a4 ed b4 80
According to unicode lookup, mentioned character should have codepoint 0x29100.
Now back to JVM spec.
Characters with code points above U+FFFF (so-called supplementary
characters) are represented by separately encoding the two surrogate
code units of their UTF-16 representation. Each of the surrogate code
units is represented by three bytes. This means supplementary
characters are represented by six bytes, u, v, w, x, y, and z :
I will not paste content here because it's too long, but you can look it up as Table 4.12. under CONSTANT_Utf8_info info (link above)
So that's why it is 6 bytes long.
Now let's take the formula
0x10000 + ((v & 0x0f) << 16) + ((w & 0x3f) << 10) +
((y & 0x0f) << 6) + (z & 0x3f)
By substituting v, w ,y and z output is 168192(10) which is 0x29100, which is expected code point.

The classic technique you can use to find that out is changing the value by something else and check the hex-dump for the difference. This was already used in the eighties when you "hacked" save games for games to increase e.g. attributes of your role playing character, etc.
I changed the character by a and it seems that the character can be found at offset 0xBE-0xC3 and has the value ED A1 A4 ED B4 80. I would have to look up the specifics of this to be able to explain why the value differs from the one you expected but Java's original support for Unicode was limited to two bytes (that's what the char type is defined. Unicode-characters with a 3+ bytes or more need to be encoded in a particular way in the Bytecode to tell the ClassLoader that it needs to be treated in a different way.

Related

Unable to create spring bean ElasticSearchTemplate

I am getting an error when launching my SpringBoot application. Below is the stacktrace -
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.core.ElasticsearchTemplate]: Factory method 'elasticsearchTemplate' threw exception; nested exception is java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
org/springframework/data/elasticsearch/core/ElasticsearchTemplate.doSearch(Lorg/elasticsearch/action/search/SearchRequestBuilder;Lorg/springframework/data/elasticsearch/core/query/SearchQuery;)Lorg/elasticsearch/action/search/SearchResponse; #306: invokevirtual
Reason:
Type 'org/elasticsearch/search/aggregations/AbstractAggregationBuilder' (current frame, stack[1]) is not assignable to 'org/elasticsearch/search/aggregations/AggregationBuilder'
Current Frame:
bci: #306
flags: { }
locals: { 'org/springframework/data/elasticsearch/core/ElasticsearchTemplate', 'org/elasticsearch/action/search/SearchRequestBuilder', 'org/springframework/data/elasticsearch/core/query/SearchQuery', 'java/util/Iterator', 'org/elasticsearch/search/aggregations/AbstractAggregationBuilder' }
stack: { 'org/elasticsearch/action/search/SearchRequestBuilder', 'org/elasticsearch/search/aggregations/AbstractAggregationBuilder' }
Bytecode:
0x0000000: 2cb9 0076 0100 c600 0e2b 2cb9 0076 0100
0x0000010: b600 7757 2cb9 015f 0100 b800 a19a 002d
0x0000020: 2cb9 015f 0100 b900 dc01 004e 2db9 00b9
0x0000030: 0100 9900 182d b900 ba01 00c0 0160 3a04
0x0000040: 2b19 04b6 0161 57a7 ffe5 2cb9 0162 0100
0x0000050: b900 b301 009a 0035 2cb9 0162 0100 b900
0x0000060: dc01 004e 2db9 00b9 0100 9900 202d b900
0x0000070: ba01 00c0 0163 3a04 2b19 04b6 0164 1904
0x0000080: b601 65b6 0166 57a7 ffdd 2cb9 0167 0100
0x0000090: c600 352c b901 6701 004e 2dbe 3604 0336
0x00000a0: 0515 0515 04a2 0020 2d15 0532 3a06 2bbb
0x00000b0: 0168 59b7 0169 1906 b601 6ab6 016b 5784
0x00000c0: 0501 a7ff df2c b901 6c01 00b8 00a1 9a00
0x00000d0: 352c b901 6c01 00b9 00dc 0100 4e2d b900
0x00000e0: b901 0099 0020 2db9 00ba 0100 c001 6d3a
0x00000f0: 042b 1904 b601 6e19 04b6 016f b601 7057
0x0000100: a7ff dd2c b901 7101 00b8 00a1 9a00 2d2c
0x0000110: b901 7101 00b9 00dc 0100 4e2d b900 b901
0x0000120: 0099 0018 2db9 00ba 0100 c001 723a 042b
0x0000130: 1904 b601 7357 a7ff e52c b901 7401 00b8
0x0000140: 00a1 9a00 322c b901 7401 00b9 00dc 0100
0x0000150: 4e2d b900 b901 0099 001d 2db9 00ba 0100
0x0000160: c001 753a 042b 1904 b901 7601 00b6 0173
0x0000170: 57a7 ffe0 2a2b 2cb9 0074 0100 b600 75b6
0x0000180: 0078 b700 79b0
Stackmap Table:
same_frame(#20)
append_frame(#44,Object[#709])
chop_frame(#74,1)
append_frame(#100,Object[#709])
chop_frame(#138,1)
append_frame(#161,Object[#828],Integer,Integer)
chop_frame(#197,3)
append_frame(#221,Object[#709])
chop_frame(#259,1)
append_frame(#283,Object[#709])
chop_frame(#313,1)
append_frame(#337,Object[#709])
chop_frame(#372,1)
I am wondering if this is related to any maven dependency conflicts. Could anybody explain what below reason means? Any help would be great.
Type
'org/elasticsearch/search/aggregations/AbstractAggregationBuilder'
(current frame, stack[1]) is not assignable to
'org/elasticsearch/search/aggregations/AggregationBuilder'

Can not compile in IntelliJ

Hello I am getting this error that I can not seem to go away. I am using IntelliJ CE current release, I have done a few fresh installs of the IDE. Nonetheless, I always get this error.
Here is the project I was working on:
My sanity check didn't work.. .
Also even more interesting…
only on the first run, when I open up any Java Project, I get this error:
Error:Internal error: (java.lang.VerifyError) Uninitialized object exists on backward branch 90
Exception Details:
Location:
org/jetbrains/kotlin/jps/build/KotlinBuilder.createCompileEnvironment(Ljava/util/Map;Lorg/jetbrains/kotlin/incremental/components/LookupTracker;Lorg/jetbrains/jps/incremental/CompileContext;Lorg/jetbrains/kotlin/jps/build/KotlinBuilder$MessageCollectorAdapter;)Lorg/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment; #171: goto
Reason:
Error exists in the bytecode
Bytecode:
0x0000000: bb03 fe59 b703 ff3a 0619 063a 0719 0713
0x0000010: 02d7 2cb6 0403 5719 0713 0405 bb04 0759
0x0000020: 2b3a 083a 093a 0a3a 0b3a 0c19 083a 0dbb
0x0000030: 0409 5919 08b9 040a 0100 b804 10b7 0411
0x0000040: c002 893a 0e19 0db9 028c 0100 c000 b03a
0x0000050: 0f19 0fb9 00b9 0100 3a10 1910 b900 be01
0x0000060: 0099 004d 1910 b900 c201 003a 1119 0e19
0x0000070: 11c0 028e 3a12 3a13 1912 b902 9101 00c0
0x0000080: 00c4 b804 173a 1419 1319 1419 11c0 028e
0x0000090: 3a15 3a16 3a17 1915 b902 9401 003a 1819
0x00000a0: 1719 1619 18b9 041b 0300 57a7 ffaf 190e
0x00000b0: 0000 3a13 190c 190b 190a 1909 1913 b704
0x00000c0: 1eb6 0403 5719 0713 0420 bb04 2259 2c2b
0x00000d0: 2db7 0425 b604 0357 1907 b604 283a 052a
0x00000e0: b704 2c3a 0619 06c6 0010 1906 b904 3101
0x00000f0: 00b6 013c 9a00 1319 04b2 0216 1304 3301
0x0000100: 0701 b801 fa01 b0bb 0262 5919 0619 05b2
0x0000110: 002e b604 3719 04c0 01c7 bb04 3959 b704
0x0000120: 3ab7 043d b0
Stackmap Table:
full_frame(#90,{Object[#2],Object[#649],Object[#727],Object[#98],Object[#428],Top,Object[#1022],Object[#1022],Object[#649],Uninitialized[#28],Uninitialized[#28],Object[#1005],Object[#1022],Object[#649],Object[#649],Object[#176],Object[#187]},{})
same_frame_extended(#174)
full_frame(#247,{Object[#2],Object[#649],Object[#727],Object[#98],Object[#428],Object[#1102],Object[#1070],Object[#1022],Object[#649],Object[#1031],Object[#1031],Object[#1005],Object[#1022],Object[#649],Object[#649],Object[#176],Object[#187],Top,Top,Object[#649]},{})
same_frame(#263)
java.lang.VerifyError: Uninitialized object exists on backward branch 90
Exception Details:
Location:
org/jetbrains/kotlin/jps/build/KotlinBuilder.createCompileEnvironment(Ljava/util/Map;Lorg/jetbrains/kotlin/incremental/components/LookupTracker;Lorg/jetbrains/jps/incremental/CompileContext;Lorg/jetbrains/kotlin/jps/build/KotlinBuilder$MessageCollectorAdapter;)Lorg/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment; #171: goto
Reason:
Error exists in the bytecode
Bytecode:
0x0000000: bb03 fe59 b703 ff3a 0619 063a 0719 0713
0x0000010: 02d7 2cb6 0403 5719 0713 0405 bb04 0759
0x0000020: 2b3a 083a 093a 0a3a 0b3a 0c19 083a 0dbb
0x0000030: 0409 5919 08b9 040a 0100 b804 10b7 0411
0x0000040: c002 893a 0e19 0db9 028c 0100 c000 b03a
0x0000050: 0f19 0fb9 00b9 0100 3a10 1910 b900 be01
0x0000060: 0099 004d 1910 b900 c201 003a 1119 0e19
0x0000070: 11c0 028e 3a12 3a13 1912 b902 9101 00c0
0x0000080: 00c4 b804 173a 1419 1319 1419 11c0 028e
0x0000090: 3a15 3a16 3a17 1915 b902 9401 003a 1819
0x00000a0: 1719 1619 18b9 041b 0300 57a7 ffaf 190e
0x00000b0: 0000 3a13 190c 190b 190a 1909 1913 b704
0x00000c0: 1eb6 0403 5719 0713 0420 bb04 2259 2c2b
0x00000d0: 2db7 0425 b604 0357 1907 b604 283a 052a
0x00000e0: b704 2c3a 0619 06c6 0010 1906 b904 3101
0x00000f0: 00b6 013c 9a00 1319 04b2 0216 1304 3301
0x0000100: 0701 b801 fa01 b0bb 0262 5919 0619 05b2
0x0000110: 002e b604 3719 04c0 01c7 bb04 3959 b704
0x0000120: 3ab7 043d b0
Stackmap Table:
full_frame(#90,{Object[#2],Object[#649],Object[#727],Object[#98],Object[#428],Top,Object[#1022],Object[#1022],Object[#649],Uninitialized[#28],Uninitialized[#28],Object[#1005],Object[#1022],Object[#649],Object[#649],Object[#176],Object[#187]},{})
same_frame_extended(#174)
full_frame(#247,{Object[#2],Object[#649],Object[#727],Object[#98],Object[#428],Object[#1102],Object[#1070],Object[#1022],Object[#649],Object[#1031],Object[#1031],Object[#1005],Object[#1022],Object[#649],Object[#649],Object[#176],Object[#187],Top,Top,Object[#649]},{})
same_frame(#263)
at org.jetbrains.kotlin.jps.build.KotlinBuilderService.createModuleLevelBuilders(KotlinBuilderService.java:30)
at org.jetbrains.jps.incremental.BuilderRegistry.<init>(BuilderRegistry.java:54)
at org.jetbrains.jps.incremental.BuilderRegistry.<init>(BuilderRegistry.java:33)
at org.jetbrains.jps.incremental.BuilderRegistry$Holder.<clinit>(BuilderRegistry.java:36)
at org.jetbrains.jps.incremental.BuilderRegistry.getInstance(BuilderRegistry.java:43)
at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:133)
at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:295)
at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:125)
at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:236)
at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$$Lambda$4/386536307.run(Unknown Source)
at org.jetbrains.jps.service.impl.SharedThreadPoolImpl.lambda$executeOnPooledThread$0(SharedThreadPoolImpl.java:42)
at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$$Lambda$2/670035812.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
also here is the first error in text:
Error:Internal error: (java.lang.NoClassDefFoundError) Could not initialize class org.jetbrains.jps.incremental.BuilderRegistry$Holder
java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.jps.incremental.BuilderRegistry$Holder
at org.jetbrains.jps.incremental.BuilderRegistry.getInstance(BuilderRegistry.java:43)
at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:133)
at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:295)
at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:125)
at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:236)
at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$$Lambda$14/473199672.run(Unknown Source)
at org.jetbrains.jps.service.impl.SharedThreadPoolImpl.lambda$executeOnPooledThread$0(SharedThreadPoolImpl.java:42)
at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$$Lambda$2/670035812.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
P.S. HALP I don’t wanna use eclipse!!!
There is an open issue logged, but the problem is not easily reproducible. It may help to update the project SDK to the most recent version (like 1.8.0_152).
Kotlin plug-in can be disabled as a workaround if you are not using it.
That's a known JDK issue: JDK-8046233
Please, update your Java installation.

java.lang.VerifyError when convert docx to html using Apache POI

I have a problem when I convert docx to html string. I use APACHE POI
InputStream is = new FileInputStream(file);
XWPFDocument document = new XWPFDocument(is);
is.close();
// 2) Prepare Html options
XHTMLOptions options = XHTMLOptions.create();
// Extract image
// 3) Convert XWPFDocument to HTML
ByteArrayOutputStream out = new ByteArrayOutputStream();
XHTMLConverter.getInstance().convert(document, out, options);
re = out.toString();
out.close();
I use
org.apache.poi.xwpf.converter.core-1.0.4.jar and org.apache.poi.xwpf.converter.xhtml-1.0.4.jar
When I run my application and I get error in console.
SEVERE: java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
cusc/cchc/util/OfficeReader.convertDocxToHtml()Ljava/lang/String; #105:
invokeinterface
Reason:
Type 'org/apache/poi/xwpf/converter/xhtml/XHTMLOptions' (current frame, stack[3]) is not assignable to 'org/apache/poi/xwpf/converter/core/Options'
Current Frame:
bci: #105
flags: { }
locals: { 'cusc/cchc/util/OfficeReader', 'java/lang/String', 'java/io/FileInputStream', 'org/apache/poi/xwpf/usermodel/XWPFDocument', 'org/apache/poi/xwpf/converter/xhtml/XHTMLOptions', 'java/io/ByteArrayOutputStream' }
stack: { 'org/apache/poi/xwpf/converter/core/IXWPFConverter', 'org/apache/poi/xwpf/usermodel/XWPFDocument', 'java/io/ByteArrayOutputStream', 'org/apache/poi/xwpf/converter/xhtml/XHTMLOptions' }
Bytecode:
0x0000000: 1212 4c2a b400 16c6 018d 2ab4 0016 b600
0x0000010: 1c99 0183 b800 59b6 005f 1400 6369 bb00
0x0000020: 6559 b800 6714 006d 6bb8 006f b700 73b6
0x0000030: 0076 8561 b800 7ab3 007e bb00 c659 2ab4
0x0000040: 0016 b700 c84d bb01 3e59 2cb7 0140 4e2c
0x0000050: b601 41b8 0144 3a04 bb01 4959 b701 4b3a
0x0000060: 05b8 014c 2d19 0519 04b9 0151 0400 1905
0x0000070: b601 574c 1905 b601 582b bb00 2d59 b201
0x0000080: 59b8 015e b700 31b2 007e b601 6113 0164
0x0000090: b601 61b6 0036 1212 b601 664c 1301 6ab8
0x00000a0: 016c 3a06 1906 2bb6 0172 3a07 b800 473a
0x00000b0: 0819 08b6 004d 3a09 1909 b600 51c0 0057
0x00000c0: 3a0a 190a 1280 b900 8202 00c0 0086 3a0b
0x00000d0: 190a b800 883a 0c19 0bb6 008e b600 923a
0x00000e0: 0d19 0c19 0d19 0bb6 0097 b900 9b01 0012
0x00000f0: a0b8 00a2 3a0e 190e 12aa 12ac b900 ae03
0x0000100: 0019 0e12 b412 b6b9 00ae 0300 190e 12b8
0x0000110: 12ba b900 ae03 0019 0e12 bc12 beb9 00ae
0x0000120: 0300 190e 12c0 12c2 b900 ae03 0019 0e12
0x0000130: c4b2 007e b900 ae03 00a7 0050 1907 04b6
0x0000140: 0176 1301 6413 017c b601 663a 0f19 0e13
0x0000150: 017e bb00 2d59 b200 7eb8 015e b700 3113
0x0000160: 0164 b601 6119 0fb6 0161 b600 36b9 00ae
0x0000170: 0300 2b19 0f13 017c 1301 64b6 0166 190e
0x0000180: b901 8001 00b6 0166 4c19 07b6 0181 9aff
0x0000190: aea7 0027 b200 2013 0121 b601 23a7 001b
0x00001a0: 4d2c b601 8412 12b0 4d2c b601 8912 12b0
0x00001b0: 4d2c b601 8c12 12b0 2bb0
Exception Handler Table:
bci [3, 413] => handler: 416
bci [3, 413] => handler: 424
bci [3, 413] => handler: 432
Stackmap Table:
full_frame(#316,{Object[#1],Object[#68],Object[#322],Object[#318],Object[#325],Object[#329],Object[#365],Object[#375],Object[#72],Object[#82],Object[#87],Object[#134],Object[#416],Object[#68],Object[#175]},{})
same_frame_extended(#393)
full_frame(#404,{Object[#1],Object[#68]},{})
same_locals_1_stack_item_frame(#416,Object[#389])
same_locals_1_stack_item_frame(#424,Object[#394])
same_locals_1_stack_item_frame(#432,Object[#397])
same_frame(#440)
I search the error in web and they say it is a problem about JDK. I use JDK 7. Help me to fix this error.
Thank all

Get headers and content sent from Java in php

Java coder sends me some data (some headers and content of picture).
It look like this:
436f 6e74 656e 742d 4c65 6e67 7468 3a20
3138 3830 0d0a 0d0a ffd8 ffe0 0010 4a46
4946 0001 0101 0060 0060 0000 ffdb 0043
0010 0b0c 0e0c 0a10 0e0d 0e12 1110 1318
281a 1816 1618 3123 251d 283a 333d 3c39
3338 3740 485c 4e40 4457 4537 3850 6d51
...
I'm trying to parse it with $queryHex=pack("H*", $query); where $query = file_get_contents("php://input");
When I try to var_dump $queryHex I get
Co�#enB�Le�pth�18�
and than some not readable symbols that I suppose to be a content of picture.
Also I tried to set encoding (header('Content-Type: text/html; charset=utf-8');) and result remains.
What I'm doing wrong? How to get propper data?
Update:
According to his API he should send something like this:
POST /url_for_detect HTTP/1.1
Content-Type: image/jpeg; boundary=-
[DATA]
DATA is a content of picture.
But there is Content-length there. He said that it's not necessary. However I stil can't see content-type there or get DATA. Asked him to send me a query that he sends.
The bytes you posted contains.
Content-Length: 1880
FF D8 FF E0 00 10 4A 46 49 46 <-- the start of the JPEG file
As #awons suggested already. Ask the sender what he send to you.
edit
Small "quick'n'dirty" code to convert the bytes into binary.
String content = "436f 6e74 656e 742d 4c65 6e67 7468 3a20"
+ "3138 3830 0d0a 0d0a ffd8 ffe0 0010 4a46"
+ "4946 0001 0101 0060 0060 0000 ffdb 0043"
+ "0010 0b0c 0e0c 0a10 0e0d 0e12 1110 1318"
+ "281a 1816 1618 3123 251d 283a 333d 3c39"
+ "3338 3740 485c 4e40 4457 4537 3850 6d51";
StringBuilder sb = new StringBuilder(content.replaceAll(" ", ""));
sb.delete(0, 48); // remove "Content-Length: 1880"
try (FileOutputStream fos = new FileOutputStream("content.jpg")) {
while (sb.length() > 2) {
fos.write(Integer.parseInt(sb.substring(0, 2), 16));
sb.delete(0, 2);
}
}

How to replicate struct.pack in java at a low level

I have been working with a client/server where the client is written in Java (Android) and the server is written in C++. I basically need to be able to pass it a dataset and have it interpret that data correctly.
I wrote a prototype in Python, as I know what its supposed to look like there. With struct.pack, it will pack the data and you can specify that it do it in network byte order (Big Endian). This is the prototype that I wrote (and this works with the server).
5 def _BuildPDUToTx(pduObj):
6 txData = struct.pack('!i i', pduObj.Src.Type, pduObj.Src.Len) #pduObj.Src.Type: 1
#pduObj.Src.Len: 16
7 txData += pduObj.Src.Value #pduObj.Src.Value: sourceid
8 txData += struct.pack('!i i', pduObj.Dst.Type, pduObj.Dst.Len) #pduObj.Dst.Type: 2
#pduObj.Dst.Len: 14
9 txData += pduObj.Dst.Value #pduObj.Dst.Value: destid
10 txData += struct.pack('!i i i i', pduObj.Metadata.Type, pduObj.Metadata.Len,\ #pduObj.Metadata.Type: 3
11 pduObj.Metadata.Status, pduObj.Metadata.Remaining) #pduObj.Metadata.Len: 16
#pduObj.Metadata.Status: 0
#pduObj.Metadata.Remaining: 0
12 txData += struct.pack('!i i', pduObj.Msg.Type, pduObj.Msg.Len) #pduObj.Msg.Type: 6
#pduObj.Msg.Len: 27
13 txData += pduObj.Msg.Value #pduObj.Msg.Value: This is the message
14 return(txData)
I ran it with some example code (the example values are the comments on the side), and I get the following if I setup a raw netcat listener on the server side (just to see what the data looks like).
0000000 0000 0100 0000 1000 [6f73 7275 6563 6469] *brackets have "sourceid"
0000010 0000 0200 0000 0e00 [6564 7473 6469] 0000 *brackets have "destid"
0000020 0300 0000 1000 0000 0000 0000 0000 0000
0000030 0600 0000 1b00 [6854 7369 6920 2073 6874 *brackets have "This is the message"
0000040 2065 656d 7373 6761 0065]
I have tried doing the same (and used the advice of Java equivalent of Python's struct.pack? and Using Java's ByteBuffer to replicate Python's struct.pack).
I used the following code:
client = new Socket(server, port);
ObjectOutputStream dos = new ObjectOutputStream(new BufferedOutputStream(client.getOutputStream()));
ByteBuffer buffer = ByteBuffer.allocate(1000);
dos.writeInt(Src.Type); // int value 1
dos.writeInt(Src.Len); // int value 16
dos.writeUTF(Src.Value); // String value "sourceid"
dos.writeInt(Dst.Type); // int value 2
dos.writeInt(Dst.Len); // int value 14
dos.writeUTF(Dst.Value); // String value "destid"
dos.writeInt(Metadata.Type); // int value 3
dos.writeInt(Metadata.Len); // int value 16
dos.writeInt(Metadata.Status); // int value 0
dos.writeInt(Metadata.Remaining); // int value 0
dos.writeInt(Msg.Type); // int value 6
dos.writeInt(Msg.Len); // int value 27
dos.writeUTF(Msg.Value); // String value "this is the message"
dos.flush();
InputStream is = client.getInputStream();
byte[] buf = new byte[Constants.ResponseSize];
is.read(buf, 0, Constants.ResponseSize);
client.close();
However, I get the following.
0000000 edac 0500 4f77 0000 0100 0000 1000 0800
0000010 [6f73 7275 6563 6469] 0000 0200 0000 0e00 *brackets have "sourceid"
0000020 0600 [6564 7473 6469] 0000 0300 0000 1000 *brackets have "destid"
0000030 0000 0000 0000 0000 0000 0600 0000 1b00
0000040 1300 [6854 7369 6920 2073 6874 2065 656d *brackets have "This is the message"
0000050 7373 6761 0065]
0000055
Java seems to be adding quite a bit of extra. Like the first two bytes dont go with anything I put in the stream. Thats followed with my value of 1 (32 bits) and 16 (the next 32 bits), but then it has 0800 before the "sourceid".
What the heck is Java doing?? And how can I get it to pack more like python?
Use DataOutputStream, not ObjectOutputStream.
ObjectOutputStream is used to ship Java objects from one JVM to another, and is primarily used by java object serialization framework.
DataOutputStream writes everything in Big Endian.
You may have to be careful, though, with writeUTF. By spec, it prepends the length of the byte sequence. This may, or may not, be what you want.

Categories