bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.48k stars 581 forks source link

a system properties casting issue in centos #289

Closed denggeng closed 5 years ago

denggeng commented 5 years ago

Hi,I have foud a problem in Centos.

java.lang.ExceptionInInitializerError: null
        at org.bytedeco.javacv.FFmpegFrameGrabber.<clinit>(FFmpegFrameGrabber.java:304)
        at com.yeezhao.minutes.api.util.AudioConverter.convert(AudioConverter.java:40)
        at com.yeezhao.minutes.api.meeting.service.VoiceMeetingService.tranlate(VoiceMeetingService.java:71)
        at com.yeezhao.minutes.api.meeting.service.VoiceMeetingService$$FastClassBySpringCGLIB$$f8d64b7.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
        at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:115)
        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)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
        at org.bytedeco.javacpp.Loader.loadProperties(Loader.java:196)
        at org.bytedeco.javacpp.Loader.loadProperties(Loader.java:136)
        at org.bytedeco.javacpp.Loader.load(Loader.java:935)
        at org.bytedeco.javacpp.avformat$Read_packet_Pointer_BytePointer_int.<clinit>(avformat.java:632)
        ... 12 common frames omitted
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

CentOS Linux release 7.2.1511 (Core)

And then,I modfied this file(https://github.com/bytedeco/javacpp/blob/master/src/main/java/org/bytedeco/javacpp/Loader.java)) , changed line 195,196 from

            String key = (String)e.getKey();
            String value = (String)e.getValue();

to

            String key = String.valueOf(e.getKey());
            String value = String.valueOf(e.getValue());

It has bean fixed.

saudet commented 5 years ago

How did you trigger that exception? In any case, we should skip over any illegal properties and ignore their values. Could you send a pull request that does that? Thanks!

denggeng commented 5 years ago

How did you trigger that exception? In any case, we should skip over any illegal properties and ignore their values. Could you send a pull request that does that? Thanks!

I am using spring boot to run a web application with tomcat. Using this block of code

            if (!(e.getKey() instanceof String) || !(e.getValue() instanceof String)) {
                logger.info(String.format("property key:%s,value:%s,value class:%s", String.valueOf(e.getKey()),
                        String.valueOf(e.getValue()), e.getValue().getClass()));
            }

, I have found the none String property value:

property key:server.port,value:11191,value class:class java.lang.Integer .

This is the port of tomcat! It looks like a Spring Boot property But I don't know how does Spring Boot set this property.

saudet commented 5 years ago

I see, so it's a bug in either Tomcat or Spring Boot. Thanks for the information!

saudet commented 5 years ago

In any case, the workaround has been included in JavaCPP 1.5. Thanks for reporting!