首页 文章 精选 留言 我的

精选列表

搜索[bug],共10000篇文章
优秀的个人博客,低调大师

Windows 10 1903 的第二次累积更新,还是存在 bug?

微软开始推出 Windows 10 1903 版本的第二次累积更新,修复了一些问题,主要有两个,第一个是Windows 事件查看器自定义视图时崩溃的问题,另一个是夜间灯关闭后无法工作的问题,他们把这次更新叫 “ 2019-06,基于 x64 的系统 (KB 4501375) 的 Windows 10 1903 版本的累积更新”。随着KB 4501375 的发布,Windows 10 1903 将升级为 18362.207。 第一个问题表现为,当在事件查看器中尝试展开、查看或创建自定义视图时,应用程序可能停止响应或关闭,在 Action 菜单中使用包含内置视图或日志的 Filter Current Log时,也可能会收到相同的错误。 微软在这次更新中还发现了一个问题:当在进行Windows 101903 的更新时,在操作系统语言改变了的设备上,Windows Sandbox 可能无法使用 “Error_file_NOT_FRED(0x80070002)”。微软正在制定解决方案,并将在即将发布的版本中提供更新。 微软还发布了“安装 Windows 101903 的兼容性更新”,“安装和恢复 Windows 10 1903 的兼容性更新”,以及“用于 Windows 10 1903 的服务堆栈更新”,Windows Update 将自动提供此更新。 安装 Windows 101903 的兼容性更新:为了更容易升级到Windows 101903 安装和恢复 Windows 10 1903 的兼容性更新:简化 Windows 10 1903 的安装和恢复体验 Windows 10 1903 的服务堆栈更新:修复可能导致 Windows 更新无法安装的问题 微软还发布了适用此次更新的 .NET Framework 3.5 和 4.8,来解决了以下问题: 改善了弱事件模式的内存分配和清理调度行为 处理弱事件清理期间可能发生的 InvalidOperationException 修复在 System.Web.Hosting.RecycleLimitMonitor+RecycleLimitMonitorSingleton.AlertProxyMonitors 中的 InvalidOperationException 错误 修复了工作流服务在取消处理期间发生未处理异常时可能陷入循环情况的问题 针对 Windows 窗体和 Windows Presentation Foundation(WPF) 应用程序,修复多重可访问性和提高 High DPI 认识的问题 但是,微软还有一个问题,就是“选择安装更新的时间“的这项高级设置在进行某些更改后消失了,对此并没有提到是否修复。 信息来源

优秀的个人博客,低调大师

Kotlin项目类找不到bug:java.lang.ClassNotFoundException: kotlin.reflect.Kotli...

一、今天在创建了一个Kotlin+Spring的项目,结果启动报错 org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at net.AppKt.main(App.kt:26) [classes/:na] Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:86) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:409) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] ... 8 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'httpPutFormContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter]: Factory method 'httpPutFormContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/KotlinReflectionInternalError at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:587) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1250) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:225) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:181) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:176) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:158) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:80) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:250) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:237) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:54) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5204) ~[tomcat-embed-core-8.5.29.jar:8.5.29] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.29.jar:8.5.29] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1421) ~[tomcat-embed-core-8.5.29.jar:8.5.29] at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1411) ~[tomcat-embed-core-8.5.29.jar:8.5.29] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_161] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_161] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_161] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_161] Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter]: Factory method 'httpPutFormContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/KotlinReflectionInternalError at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] ... 24 common frames omitted Caused by: java.lang.NoClassDefFoundError: kotlin/reflect/KotlinReflectionInternalError at com.fasterxml.jackson.module.kotlin.KotlinModule.setupModule(KotlinModule.kt:44) ~[jackson-module-kotlin-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:751) ~[jackson-databind-2.9.5.jar:2.9.5] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:766) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:624) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:608) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.<init>(MappingJackson2HttpMessageConverter.java:59) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.<init>(AllEncompassingFormHttpMessageConverter.java:74) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.web.filter.HttpPutFormContentFilter.<init>(HttpPutFormContentFilter.java:64) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter.<init>(OrderedHttpPutFormContentFilter.java:29) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.httpPutFormContentFilter(WebMvcAutoConfiguration.java:163) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238.CGLIB$httpPutFormContentFilter$1(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238$$FastClassBySpringCGLIB$$9f061c7c.invoke(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238.httpPutFormContentFilter(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] ... 25 common frames omitted Caused by: java.lang.ClassNotFoundException: kotlin.reflect.KotlinReflectionInternalError at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_161] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_161] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~[na:1.8.0_161] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_161] ... 45 common frames omitted 二、一看到这么多错误日志,很多同学直接懵了,其实有用的就在最后两个Caused By Caused by: java.lang.NoClassDefFoundError: kotlin/reflect/KotlinReflectionInternalError at com.fasterxml.jackson.module.kotlin.KotlinModule.setupModule(KotlinModule.kt:44) ~[jackson-module-kotlin-2.8.4.jar:2.8.4] at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:751) ~[jackson-databind-2.9.5.jar:2.9.5] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:766) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:624) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:608) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.<init>(MappingJackson2HttpMessageConverter.java:59) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.<init>(AllEncompassingFormHttpMessageConverter.java:74) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.web.filter.HttpPutFormContentFilter.<init>(HttpPutFormContentFilter.java:64) ~[spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter.<init>(OrderedHttpPutFormContentFilter.java:29) ~[spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.httpPutFormContentFilter(WebMvcAutoConfiguration.java:163) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238.CGLIB$httpPutFormContentFilter$1(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238$$FastClassBySpringCGLIB$$9f061c7c.invoke(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$f2471238.httpPutFormContentFilter(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] ... 25 common frames omitted Caused by: java.lang.ClassNotFoundException: kotlin.reflect.KotlinReflectionInternalError at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_161] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_161] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~[na:1.8.0_161] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_161] ... 45 common frames omitted 三、下面我们来google搜一搜 java.lang.ClassNotFoundException: kotlin.reflect.Kotlin Reflect Internal Error 四、点击第一个看一看 这里写链接内容 这个高分哥们说,他升级了Kotlin版本和Jackson版本后就好了 五、那么我们也来更新一下 1.先来更新Kotlin的版本,1.2.30 2.再来搜搜,看看jackson-module-kotlin:版本更新到哪里了 以前配的是2.8.4,可能太老了 compile "com.fasterxml.jackson.module:jackson-module-kotlin:2.8.4" maven仓库 3.将2.9版本的配上去 六、启动成功了,现在问题解决了 好啦,结束啦!

优秀的个人博客,低调大师

黑客也看《人民的名义》:把手机卡扔马桶有 bug

自从《人民的名义》的导演在接受媒体采访时表示,有点担心这部剧随时会断播时,雷锋网编辑就领会了这层意思:赶紧看,且看且珍惜。 果不其然,这部剧最近有点火。剧情是这样开始的: “一位国家部委的项目处长被人举报受贿千万,当最高人民检察院反贪总局侦查处处长侯亮平前来搜查时,看到的却是一位长相憨厚、衣着朴素的“老农民”在简陋破败的旧房里吃炸酱面。 当这位腐败分子的面具被最终撕开的同时,与之案件牵连甚紧的 H 省京州市副市长丁义珍,却在一位神秘人物的暗中相助下,以反侦察手段逃脱法网,流亡海外。案件线索终定位于由京州光明峰项目引发的一家H省国企大风服装厂的股权争夺,牵连其中的各派政治势力却盘根错节,扑朔迷离。” 在大家为展现的反腐尺度和紧张剧情欢欣鼓舞时,雷锋网编辑却发现了一些“不一样”的信息。尤其是,雷锋网发现,神秘人物将给丁义珍通风报信的手机卡

优秀的个人博客,低调大师

【我的Android进阶之旅】 解决bug: Expected file scheme in URI: content://download...

一、错误描述 今天测试MM用HTC手机测试某个模块的时候crash了,抓log后发现是使用DownloadManager下载apk安装包然后自动安装的时候,抛了异常:java.lang.IllegalArgumentException: Expected file scheme in URI: content://downloads/my_downloads/12 具体crash错误信息如下所示: 11-30 09:24:21.933 28279 28279 E AndroidRuntime: FATAL EXCEPTION: main 11-30 09:24:21.933 28279 28279 E AndroidRuntime: Process: com.xtc.watch, PID: 28279 11-30 09:24:21.933 28279 28279 E AndroidRuntime: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.DOWNLOAD_COMPLETE flg=0x10 pkg=com.xtc.watch (has extras) } in com.xtc.watch.service.compatible.VersionCompatibleUpdateService$DownloadCompleteReceiver@33fa7ec 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:934) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.os.Looper.loop(Looper.java:168) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5885) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Expected file scheme in URI: content://downloads/my_downloads/12 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at java.io.File.checkURI(File.java:223) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at java.io.File.<init>(File.java:175) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at com.xtc.watch.service.compatible.VersionCompatibleUpdateService.a(Unknown Source) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at com.xtc.watch.service.compatible.VersionCompatibleUpdateService.a(Unknown Source) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at com.xtc.watch.service.compatible.VersionCompatibleUpdateService$DownloadCompleteReceiver.onReceive(Unknown Source) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:915) 11-30 09:24:21.933 28279 28279 E AndroidRuntime: ... 7 more 11-30 09:24:21.939 1785 3503 E ActivityManager: App crashed! Process: com.xtc.watch 二、错误分析 进入File.java查看代码, /** * Constructs a new File using the path of the specified URI. {@code uri} * needs to be an absolute and hierarchical Unified Resource Identifier with * file scheme and non-empty path component, but with undefined authority, * query or fragment components. * * @param uri * the Unified Resource Identifier that is used to construct this * file. * @throws IllegalArgumentException * if {@code uri} does not comply with the conditions above. * @see #toURI * @see java.net.URI */ public File(URI uri) { // check pre-conditions checkURI(uri); this.path = fixSlashes(uri.getPath()); } checkURI(URI uri)的源代码如下: private static void checkURI(URI uri) { if (!uri.isAbsolute()) { throw new IllegalArgumentException("URI is not absolute: " + uri); } else if (!uri.getRawSchemeSpecificPart().startsWith("/")) { throw new IllegalArgumentException("URI is not hierarchical: " + uri); } if (!"file".equals(uri.getScheme())) { throw new IllegalArgumentException("Expected file scheme in URI: " + uri); } String rawPath = uri.getRawPath(); if (rawPath == null || rawPath.isEmpty()) { throw new IllegalArgumentException("Expected non-empty path in URI: " + uri); } if (uri.getRawAuthority() != null) { throw new IllegalArgumentException("Found authority in URI: " + uri); } if (uri.getRawQuery() != null) { throw new IllegalArgumentException("Found query in URI: " + uri); } if (uri.getRawFragment() != null) { throw new IllegalArgumentException("Found fragment in URI: " + uri); } } 原来就是下面这一段代码抛出的异常,如果uri不是以file开头的就抛异常IllegalArgumentException(“Expected file scheme in URI: ” + uri), if (!"file".equals(uri.getScheme())) { throw new IllegalArgumentException("Expected file scheme in URI: " + uri); } 而我们的uri 是通过下面代码获取而来的 Uri downloadFileUri = manager.getUriForDownloadedFile(downId); File file = new File(new URI(downloadFileUri.toString())); 得到的uri信息为 content://downloads/my_downloads/12 因此就抛了该异常出来。 getUriForDownloadedFile(long id)源代码如下: /** * Returns the {@link Uri} of the given downloaded file id, if the file is * downloaded successfully. Otherwise, null is returned. *<p> * If the specified downloaded file is in external storage (for example, /sdcard dir), * then it is assumed to be safe for anyone to read and the returned {@link Uri} corresponds * to the filepath on sdcard. * * @param id the id of the downloaded file. * @return the {@link Uri} of the given downloaded file id, if download was successful. null * otherwise. */ public Uri getUriForDownloadedFile(long id) { // to check if the file is in cache, get its destination from the database Query query = new Query().setFilterById(id); Cursor cursor = null; try { cursor = query(query); if (cursor == null) { return null; } if (cursor.moveToFirst()) { int status = cursor.getInt(cursor.getColumnIndexOrThrow(COLUMN_STATUS)); if (DownloadManager.STATUS_SUCCESSFUL == status) { int indx = cursor.getColumnIndexOrThrow( Downloads.Impl.COLUMN_DESTINATION); int destination = cursor.getInt(indx); // TODO: if we ever add API to DownloadManager to let the caller specify // non-external storage for a downloaded file, then the following code // should also check for that destination. if (destination == Downloads.Impl.DESTINATION_CACHE_PARTITION || destination == Downloads.Impl.DESTINATION_SYSTEMCACHE_PARTITION || destination == Downloads.Impl.DESTINATION_CACHE_PARTITION_NOROAMING || destination == Downloads.Impl.DESTINATION_CACHE_PARTITION_PURGEABLE) { // return private uri return ContentUris.withAppendedId(Downloads.Impl.CONTENT_URI, id); } else { // return public uri String path = cursor.getString( cursor.getColumnIndexOrThrow(COLUMN_LOCAL_FILENAME)); return Uri.fromFile(new File(path)); } } } } finally { if (cursor != null) { cursor.close(); } } // downloaded file not found or its status is not 'successfully completed' return null; } 三、错误解决 将之前查找下载好的apk文件的代码 Uri downloadFileUri = manager.getUriForDownloadedFile(downId); File file = new File(new URI(downloadFileUri.toString())); 改为通过downId来查询DownloadManager下载的数据库的记录,然后查找本地文件的路径,如下所示: Cursor c = manager.query(new DownloadManager.Query().setFilterById(downId)); if(c != null){ c.moveToFirst(); int fileNameIdx = c.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME); String fileName = c.getString(fileNameIdx); File file = new File(fileName); LogUtil.d(TAG, "安装文件:" + file.getAbsolutePath()); c.close(); } 安装apk的代码由 //自动安装apk Intent install = new Intent(Intent.ACTION_VIEW); install.setDataAndType(downloadFileUri, "application/vnd.android.package-archive"); install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(install); 改为 //自动安装apk Intent install = new Intent(Intent.ACTION_VIEW); //install.setDataAndType(downloadFileUri, "application/vnd.android.package-archive"); install.setDataAndType(Uri.parse("file://" + fileName.toString()), "application/vnd.android.package-archive"); install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(install); 这样通过查询本地真实的下载好apk的真实本地路径,然后再进行安装的话就不会报异常了。 参考文章: http://blog.csdn.net/q445697127/article/details/40537945 http://www.xuebuyuan.com/2163407.html http://www.2cto.com/kf/201502/376975.html 作者:欧阳鹏 欢迎转载,与人分享是进步的源泉! 转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/53404379

优秀的个人博客,低调大师

React 中 useEffect 依赖数组引发的无限循环:从真实 bug 到正确写法

在使用 React 函数组件开发时,useEffect 的依赖数组是一个经常被忽视却又极易引发问题的点。很多开发者在处理数据获取、事件监听或状态同步时,会不小心把对象、函数或数组直接放进依赖数组,结果组件陷入无限重渲染循环,控制台不停打印请求日志,页面卡死甚至触发浏览器警告。这个问题在真实项目中非常常见,尤其是在从类组件迁移到 Hooks 或者编写自定义 Hook 时。常见原因包括在 useEffect 内部创建了新对象或新函数并放入依赖数组、将父组件传递的回调函数未做缓存直接使用、以及在 effect 中更新了自身依赖的状态。文章围绕一个真实的无限循环案例,分析依赖比较机制、闭包陷阱,并给出 useMemo、useCallback 以及函数式更新的落地写法。 先看一段会出问题的代码: ```jsx function UserProfile({ userId }) { const [user, setUser] = useState(null); const [loading, setLoading] = useState(false); useEffect(() => { setLoading(true); fetch(`/api/users/${userId}`) .then(res => res.json()) .then(data => { setUser(data); setLoading(false); }); }, [userId, user]); // 这里把 user 放进依赖 return loading ? 加载中... : {user?.name}; } ``` 这个 effect 依赖了 user,而 effect 内部又调用了 setUser,每次请求成功 user 变化,effect 重新执行,再次请求,形成无限循环。实际开发中类似的场景还包括:在 effect 中调用 setState 但依赖数组里放了那个 state;或者依赖了一个在组件体内声明的函数,而该函数每次渲染都会重新创建。 依赖数组的比较是浅比较,React 用 Object.is 比较每一项。对于对象和函数,引用不同就会触发 effect 重跑。很多人会想直接去掉依赖数组来“解决”问题,但这样 effect 会在每次渲染后执行,同样会导致循环,而且会丢失对特定依赖变化的精确控制。正确做法是梳理 effect 真正依赖的外部值。上面的例子中,effect 只需要在 userId 变化时重新请求,所以依赖数组应该只包含 userId: ```jsx useEffect(() => { let cancelled = false; setLoading(true); fetch(`/api/users/${userId}`) .then(res => res.json()) .then(data => { if (!cancelled) { setUser(data); setLoading(false); } }); return () => { cancelled = true; }; }, [userId]); ``` 这里还顺便处理了请求竞态:当 userId 快速变化时,旧请求返回后不应该覆盖新状态。清理函数里设置 cancelled 是常见手段,也可以用 AbortController。 另一种常见情况是依赖了父组件传入的回调函数。比如: ```jsx function Parent() { const [count, setCount] = useState(0); const handleSave = () => { console.log('save', count); }; return ; } function Child({ onSave }) { useEffect(() => { onSave(); }, [onSave]); // onSave 每次渲染都是新函数,导致无限循环 } ``` Child 的 effect 依赖 onSave,而 Parent 每次渲染都会创建新的 handleSave,于是 Child 的 effect 每次都会执行,如果 onSave 内部又触发 Parent 状态更新,循环就成立了。解决方式是用 useCallback 稳定函数引用,并且把 count 放进依赖: ```jsx const handleSave = useCallback(() => { console.log('save', count); }, [count]); ``` 如果 Child 只是想在挂载时执行一次,那依赖数组应该写空数组,但要确认 onSave 在生命周期内不会变化,或者用 ref 保存最新回调。 对于对象依赖,常见场景是配置对象。比如: ```jsx function Editor({ config }) { useEffect(() => { applyConfig(config); }, [config]); } ``` 如果父组件每次渲染都传一个新的 config 对象,effect 就会频繁执行。可以在父组件用 useMemo 缓存 config,或者在子组件用 useRef 保存上一次的 config 做深比较,但深比较要谨慎,避免性能开销。实际项目里尽量让配置对象在父组件稳定下来。 函数式更新也能避免把 state 放进依赖。比如一个计数器需要在 effect 中基于旧值更新: ```jsx useEffect(() => { const timer = setInterval(() => { setCount(c => c + 1); }, 1000); return () => clearInterval(timer); }, []); // 不需要把 count 放进依赖 ``` 如果写成 setCount(count + 1),就必须把 count 放进依赖,导致 interval 每次重建。函数式更新让 effect 只依赖 setCount(React 保证其稳定),从而避免循环。 依赖数组问题的本质是 effect 与渲染周期之间的关系。每次渲染都会生成新的闭包,effect 捕获的是那次渲染的值。不加依赖会让 effect 看到旧值,加了不稳定的依赖又会导致频繁执行。排查时可以在 effect 里打印依赖值,观察引用是否变化;也可以使用 eslint-plugin-react-hooks 的 exhaustive-deps 规则,它会提示缺失的依赖,但不要盲目自动修复,要结合业务判断。对于确实不想因为某个值变化而重跑 effect 的场景,可以用 useRef 保存该值,在 effect 内读取 ref.current,这样依赖数组里就不需要放它。 真实项目里还有一个容易忽略的点:在 effect 中调用 setState 时,如果新状态和旧状态相同,React 可能会跳过重渲染,但如果状态是对象且每次都新建,就会触发渲染。比如 setUser({ ...user, name: 'x' }) 即使内容一样也是新引用,依赖 user 的 effect 会再次执行。尽量让状态更新返回相同引用(React 在 useState 中如果返回相同值会 bail out),或者把依赖拆细。 理解这些后,写 useEffect 时先问自己:这个 effect 到底依赖哪些外部变量?这些变量在每次渲染时引用是否稳定?如果 effect 内部更新了状态,这个状态是否必须出现在依赖里?多数无限循环都是因为把 effect 内部产生的值放进了依赖,或者依赖了每次渲染都新建的函数和对象。把依赖收窄到真正的外部输入,用 useCallback/useMemo 稳定引用,用函数式更新和 ref 处理不需要触发重跑的值,就能避免大部分问题。 推荐查看天气:http://www.tianqi556.com/chengyu/5100.html 推荐查看天气:http://www.tianqi556.com/chengyu/5101.html 推荐查看天气:http://www.tianqi556.com/chengyu/5102.html 推荐查看天气:http://www.tianqi556.com/chengyu/5103.html 推荐查看天气:http://www.tianqi556.com/chengyu/5104.html 推荐查看天气:http://www.tianqi556.com/chengyu/5105.html 推荐查看天气:http://www.tianqi556.com/chengyu/5106.html 推荐查看天气:http://www.tianqi556.com/chengyu/5107.html 推荐查看天气:http://www.tianqi556.com/chengyu/5108.html 推荐查看天气:http://www.tianqi556.com/chengyu/5109.html 推荐查看天气:http://www.tianqi556.com/chengyu/5110.html 推荐查看天气:http://www.tianqi556.com/chengyu/5111.html 推荐查看天气:http://www.tianqi556.com/chengyu/5112.html 推荐查看天气:http://www.tianqi556.com/chengyu/5113.html 推荐查看天气:http://www.tianqi556.com/chengyu/5114.html 推荐查看天气:http://www.tianqi556.com/chengyu/5115.html 推荐查看天气:http://www.tianqi556.com/chengyu/5116.html 推荐查看天气:http://www.tianqi556.com/chengyu/5117.html 推荐查看天气:http://www.tianqi556.com/chengyu/5118.html 推荐查看天气:http://www.tianqi556.com/chengyu/5119.html 推荐查看天气:http://www.tianqi556.com/chengyu/5120.html 推荐查看天气:http://www.tianqi556.com/chengyu/5121.html 推荐查看天气:http://www.tianqi556.com/chengyu/5122.html 推荐查看天气:http://www.tianqi556.com/chengyu/5123.html 推荐查看天气:http://www.tianqi556.com/chengyu/5124.html 推荐查看天气:http://www.tianqi556.com/chengyu/5125.html 推荐查看天气:http://www.tianqi556.com/chengyu/5126.html 推荐查看天气:http://www.tianqi556.com/chengyu/5127.html 推荐查看天气:http://www.tianqi556.com/chengyu/5128.html 推荐查看天气:http://www.tianqi556.com/chengyu/5129.html 推荐查看天气:http://www.tianqi556.com/chengyu/5130.html 推荐查看天气:http://www.tianqi556.com/chengyu/5131.html 推荐查看天气:http://www.tianqi556.com/chengyu/5132.html 推荐查看天气:http://www.tianqi556.com/chengyu/5133.html 推荐查看天气:http://www.tianqi556.com/chengyu/5134.html 推荐查看天气:http://www.tianqi556.com/chengyu/5135.html 推荐查看天气:http://www.tianqi556.com/chengyu/5136.html 推荐查看天气:http://www.tianqi556.com/chengyu/5137.html 推荐查看天气:http://www.tianqi556.com/chengyu/5138.html 推荐查看天气:http://www.tianqi556.com/chengyu/5139.html 推荐查看天气:http://www.tianqi556.com/chengyu/5140.html 推荐查看天气:http://www.tianqi556.com/chengyu/5141.html 推荐查看天气:http://www.tianqi556.com/chengyu/5142.html 推荐查看天气:http://www.tianqi556.com/chengyu/5143.html 推荐查看天气:http://www.tianqi556.com/chengyu/5144.html 推荐查看天气:http://www.tianqi556.com/chengyu/5145.html 推荐查看天气:http://www.tianqi556.com/chengyu/5146.html 推荐查看天气:http://www.tianqi556.com/chengyu/5147.html 推荐查看天气:http://www.tianqi556.com/chengyu/5148.html 推荐查看天气:http://www.tianqi556.com/chengyu/5149.html 推荐查看天气:http://www.tianqi556.com/chengyu/5150.html 推荐查看天气:http://www.tianqi556.com/chengyu/5151.html 推荐查看天气:http://www.tianqi556.com/chengyu/5152.html 推荐查看天气:http://www.tianqi556.com/chengyu/5153.html 推荐查看天气:http://www.tianqi556.com/chengyu/5154.html 推荐查看天气:http://www.tianqi556.com/chengyu/5155.html 推荐查看天气:http://www.tianqi556.com/chengyu/5156.html 推荐查看天气:http://www.tianqi556.com/chengyu/5157.html 推荐查看天气:http://www.tianqi556.com/chengyu/5158.html 推荐查看天气:http://www.tianqi556.com/chengyu/5159.html 推荐查看天气:http://www.tianqi556.com/chengyu/5160.html 推荐查看天气:http://www.tianqi556.com/chengyu/5161.html 推荐查看天气:http://www.tianqi556.com/chengyu/5162.html 推荐查看天气:http://www.tianqi556.com/chengyu/5163.html 推荐查看天气:http://www.tianqi556.com/chengyu/5164.html 推荐查看天气:http://www.tianqi556.com/chengyu/5165.html 推荐查看天气:http://www.tianqi556.com/chengyu/5166.html 推荐查看天气:http://www.tianqi556.com/chengyu/5167.html 推荐查看天气:http://www.tianqi556.com/chengyu/5168.html 推荐查看天气:http://www.tianqi556.com/chengyu/5169.html 推荐查看天气:http://www.tianqi556.com/chengyu/5170.html 推荐查看天气:http://www.tianqi556.com/chengyu/5171.html 推荐查看天气:http://www.tianqi556.com/chengyu/5172.html 推荐查看天气:http://www.tianqi556.com/chengyu/5173.html 推荐查看天气:http://www.tianqi556.com/chengyu/5174.html 推荐查看天气:http://www.tianqi556.com/chengyu/5175.html 推荐查看天气:http://www.tianqi556.com/chengyu/5176.html 推荐查看天气:http://www.tianqi556.com/chengyu/5177.html 推荐查看天气:http://www.tianqi556.com/chengyu/5178.html 推荐查看天气:http://www.tianqi556.com/chengyu/5179.html 推荐查看天气:http://www.tianqi556.com/chengyu/5180.html 推荐查看天气:http://www.tianqi556.com/chengyu/5181.html 推荐查看天气:http://www.tianqi556.com/chengyu/5182.html 推荐查看天气:http://www.tianqi556.com/chengyu/5183.html 推荐查看天气:http://www.tianqi556.com/chengyu/5184.html 推荐查看天气:http://www.tianqi556.com/chengyu/5185.html 推荐查看天气:http://www.tianqi556.com/chengyu/5186.html 推荐查看天气:http://www.tianqi556.com/chengyu/5187.html 推荐查看天气:http://www.tianqi556.com/chengyu/5188.html 推荐查看天气:http://www.tianqi556.com/chengyu/5189.html 推荐查看天气:http://www.tianqi556.com/chengyu/5190.html 推荐查看天气:http://www.tianqi556.com/chengyu/5191.html 推荐查看天气:http://www.tianqi556.com/chengyu/5192.html 推荐查看天气:http://www.tianqi556.com/chengyu/5193.html 推荐查看天气:http://www.tianqi556.com/chengyu/5194.html 推荐查看天气:http://www.tianqi556.com/chengyu/5195.html 推荐查看天气:http://www.tianqi556.com/chengyu/5196.html 推荐查看天气:http://www.tianqi556.com/chengyu/5197.html 推荐查看天气:http://www.tianqi556.com/chengyu/5198.html 推荐查看天气:http://www.tianqi556.com/chengyu/5199.html 推荐查看天气:http://www.tianqi556.com/chengyu/5200.html 推荐查看天气:http://www.tianqi556.com/chengyu/5201.html 推荐查看天气:http://www.tianqi556.com/chengyu/5202.html 推荐查看天气:http://www.tianqi556.com/chengyu/5203.html 推荐查看天气:http://www.tianqi556.com/chengyu/5204.html 推荐查看天气:http://www.tianqi556.com/chengyu/5205.html 推荐查看天气:http://www.tianqi556.com/chengyu/5206.html 推荐查看天气:http://www.tianqi556.com/chengyu/5207.html 推荐查看天气:http://www.tianqi556.com/chengyu/5208.html 推荐查看天气:http://www.tianqi556.com/chengyu/5209.html 推荐查看天气:http://www.tianqi556.com/chengyu/5210.html 推荐查看天气:http://www.tianqi556.com/chengyu/5211.html 推荐查看天气:http://www.tianqi556.com/chengyu/5212.html 推荐查看天气:http://www.tianqi556.com/chengyu/5213.html 推荐查看天气:http://www.tianqi556.com/chengyu/5214.html 推荐查看天气:http://www.tianqi556.com/chengyu/5215.html 推荐查看天气:http://www.tianqi556.com/chengyu/5216.html 推荐查看天气:http://www.tianqi556.com/chengyu/5217.html 推荐查看天气:http://www.tianqi556.com/chengyu/5218.html 推荐查看天气:http://www.tianqi556.com/chengyu/5219.html 推荐查看天气:http://www.tianqi556.com/chengyu/5220.html 推荐查看天气:http://www.tianqi556.com/chengyu/5221.html 推荐查看天气:http://www.tianqi556.com/chengyu/5222.html 推荐查看天气:http://www.tianqi556.com/chengyu/5223.html 推荐查看天气:http://www.tianqi556.com/chengyu/5224.html 推荐查看天气:http://www.tianqi556.com/chengyu/5225.html 推荐查看天气:http://www.tianqi556.com/chengyu/5226.html 推荐查看天气:http://www.tianqi556.com/chengyu/5227.html 推荐查看天气:http://www.tianqi556.com/chengyu/5228.html 推荐查看天气:http://www.tianqi556.com/chengyu/5229.html 推荐查看天气:http://www.tianqi556.com/chengyu/5230.html 推荐查看天气:http://www.tianqi556.com/chengyu/5231.html 推荐查看天气:http://www.tianqi556.com/chengyu/5232.html 推荐查看天气:http://www.tianqi556.com/chengyu/5233.html 推荐查看天气:http://www.tianqi556.com/chengyu/5234.html 推荐查看天气:http://www.tianqi556.com/chengyu/5235.html 推荐查看天气:http://www.tianqi556.com/chengyu/5236.html 推荐查看天气:http://www.tianqi556.com/chengyu/5237.html 推荐查看天气:http://www.tianqi556.com/chengyu/5238.html 推荐查看天气:http://www.tianqi556.com/chengyu/5239.html 推荐查看天气:http://www.tianqi556.com/chengyu/5240.html 推荐查看天气:http://www.tianqi556.com/chengyu/5241.html 推荐查看天气:http://www.tianqi556.com/chengyu/5242.html 推荐查看天气:http://www.tianqi556.com/chengyu/5243.html 推荐查看天气:http://www.tianqi556.com/chengyu/5244.html 推荐查看天气:http://www.tianqi556.com/chengyu/5245.html 推荐查看天气:http://www.tianqi556.com/chengyu/5246.html 推荐查看天气:http://www.tianqi556.com/chengyu/5247.html 推荐查看天气:http://www.tianqi556.com/chengyu/5248.html 推荐查看天气:http://www.tianqi556.com/chengyu/5249.html 推荐查看天气:http://www.tianqi556.com/chengyu/5250.html 推荐查看天气:http://www.tianqi556.com/chengyu/5251.html 推荐查看天气:http://www.tianqi556.com/chengyu/5252.html 推荐查看天气:http://www.tianqi556.com/chengyu/5253.html 推荐查看天气:http://www.tianqi556.com/chengyu/5254.html 推荐查看天气:http://www.tianqi556.com/chengyu/5255.html 推荐查看天气:http://www.tianqi556.com/chengyu/5256.html 推荐查看天气:http://www.tianqi556.com/chengyu/5257.html 推荐查看天气:http://www.tianqi556.com/chengyu/5258.html 推荐查看天气:http://www.tianqi556.com/chengyu/5259.html 推荐查看天气:http://www.tianqi556.com/chengyu/5260.html 推荐查看天气:http://www.tianqi556.com/chengyu/5261.html 推荐查看天气:http://www.tianqi556.com/chengyu/5262.html 推荐查看天气:http://www.tianqi556.com/chengyu/5263.html 推荐查看天气:http://www.tianqi556.com/chengyu/5264.html 推荐查看天气:http://www.tianqi556.com/chengyu/5265.html 推荐查看天气:http://www.tianqi556.com/chengyu/5266.html 推荐查看天气:http://www.tianqi556.com/chengyu/5267.html 推荐查看天气:http://www.tianqi556.com/chengyu/5268.html 推荐查看天气:http://www.tianqi556.com/chengyu/5269.html 推荐查看天气:http://www.tianqi556.com/chengyu/5270.html 推荐查看天气:http://www.tianqi556.com/chengyu/5271.html 推荐查看天气:http://www.tianqi556.com/chengyu/5272.html 推荐查看天气:http://www.tianqi556.com/chengyu/5273.html 推荐查看天气:http://www.tianqi556.com/chengyu/5274.html 推荐查看天气:http://www.tianqi556.com/chengyu/5275.html 推荐查看天气:http://www.tianqi556.com/chengyu/5276.html 推荐查看天气:http://www.tianqi556.com/chengyu/5277.html 推荐查看天气:http://www.tianqi556.com/chengyu/5278.html 推荐查看天气:http://www.tianqi556.com/chengyu/5279.html 推荐查看天气:http://www.tianqi556.com/chengyu/5280.html 推荐查看天气:http://www.tianqi556.com/chengyu/5281.html 推荐查看天气:http://www.tianqi556.com/chengyu/5282.html 推荐查看天气:http://www.tianqi556.com/chengyu/5283.html 推荐查看天气:http://www.tianqi556.com/chengyu/5284.html 推荐查看天气:http://www.tianqi556.com/chengyu/5285.html 推荐查看天气:http://www.tianqi556.com/chengyu/5286.html 推荐查看天气:http://www.tianqi556.com/chengyu/5287.html 推荐查看天气:http://www.tianqi556.com/chengyu/5288.html 推荐查看天气:http://www.tianqi556.com/chengyu/5289.html 推荐查看天气:http://www.tianqi556.com/chengyu/5290.html 推荐查看天气:http://www.tianqi556.com/chengyu/5291.html 推荐查看天气:http://www.tianqi556.com/chengyu/5292.html 推荐查看天气:http://www.tianqi556.com/chengyu/5293.html 推荐查看天气:http://www.tianqi556.com/chengyu/5294.html 推荐查看天气:http://www.tianqi556.com/chengyu/5295.html 推荐查看天气:http://www.tianqi556.com/chengyu/5296.html 推荐查看天气:http://www.tianqi556.com/chengyu/5297.html 推荐查看天气:http://www.tianqi556.com/chengyu/5298.html 推荐查看天气:http://www.tianqi556.com/chengyu/5299.html

优秀的个人博客,低调大师

AI全自动测试工具,自动发现并修app中的bug

Strix是一款开源的人工智能渗透测试工具,用于发现并修复app中的漏洞。 全新功能:Strix 与 GitHub Actions 以及 CI/CD 管道无缝集成。在每次拉取请求时自动扫描漏洞,并在不安全代码进入生产环境之前予以阻止 - 无需任何设置即可上手。 ![](https://developer.qcloudimg.com/http-save/yehe-12670711/7105ce328a6be74fdc7b50af221d1dfa.png) **Strix概述** Strix是自主式人工智能渗透测试代理,其行为就像真正的黑客一样——它们动态运行你的代码,发现漏洞,并通过实际的概念验证来验证这些漏洞。专为需要快速、准确的安全测试,同时又不想承担手动渗透测试的繁重工作或静态分析工具的误报问题的开发人员和安全团队而打造。 **核心能力:** 完整的渗透测试工具包——开箱即用地进行侦察、利用和验证 多代理编排——协作且可扩展的人工智能渗透测试团队 真实漏洞利用验证——提供可用的概念验证,而不像传统漏洞扫描器那样出现误报 以开发者为优先的命令行界面——带有补救指导的可操作发现 自动修复与报告——生成补丁和符合合规要求的渗透测试报告 **适用案例:** 应用程序安全测试 - 检测并验证应用程序中的关键漏洞 快速渗透测试 - 在数小时内完成渗透测试,而非数周,并生成合规报告 漏洞赏金自动化 - 自动化漏洞赏金研究并生成漏洞证明,以便更快报告 持续集成/持续交付(CI/CD)集成 - 在CI/CD中运行测试,在漏洞进入生产环境前进行拦截 **快速入门:** 前提条件: Docker(已运行) 来自任何受支持提供商(OpenAI、Anthropic、谷歌等)的大语言模型API密钥 **安装与首次扫描:** # Install Strix curl -sSL https://strix.ai/install | bash # Configure your AI provider export STRIX_LLM="openai/gpt-5.4" export LLM_API_KEY="your-api-key" # Run your first security assessment strix --target ./app-directory **注意** 首次运行会自动拉取沙盒Docker镜像。结果将保存到strix_runs/ **☁️ Strix平台** 在app.strix.ai试用Strix全栈渗透测试平台 - 免费注册,连接您的代码库和域名,几分钟内即可启动渗透测试。 带有概念验证的已验证结果 - 每个漏洞都包含可用的概念验证漏洞利用和重现步骤 一键自动修复 - 人工智能生成的安全补丁,可作为随时合并的拉取请求 持续渗透测试 - 持续进行漏洞扫描,与您的部署保持同步 开发安全运维集成 - 支持GitHub、GitLab、Bitbucket、Slack、Jira、Linear和CI/CD管道 持续学习 - 人工智能基于过去的发现进行学习,适应您的代码库,并随着时间的推移减少误报 **✨ 功能特性** 智能渗透测试工具 Strix 智能体配备了一套全面的进攻性安全工具包,其中包含专业渗透测试人员和道德黑客使用的相同工具: HTTP 拦截代理 - 借助 Caido 进行完整的请求/响应操作与分析 浏览器漏洞利用 - 用于测试跨站脚本攻击(XSS)、跨站请求伪造(CSRF)、点击劫持以及身份验证绕过流程的自动化浏览器 Shell 与命令执行 - 用于漏洞利用开发和后渗透阶段的交互式终端 自定义漏洞利用运行时 - 用于编写和验证概念验证漏洞利用的 Python 沙盒 侦察与开源情报(OSINT) - 自动进行攻击面映射、子域名枚举和指纹识别 静态与动态代码分析 - 具备静态应用安全测试(SAST)和动态应用安全测试(DAST)功能,用于全面的应用程序安全测试 漏洞知识库 - 带有通用漏洞评分系统(CVSS)评分和开放式 Web 应用程序安全项目(OWASP)分类的结构化检测结果 全面漏洞扫描器 Strix可识别、验证并利用OWASP十大漏洞及其他广泛的安全漏洞: 访问控制失效 - IDOR(未授权直接对象引用)、权限提升、身份验证绕过 注入攻击 - SQL注入、NoSQL注入、操作系统命令注入、服务器端模板注入 服务器端漏洞 - SSRF(服务器端请求伪造)、XXE(XML外部实体注入)、不安全的反序列化、远程代码执行 客户端攻击 - XSS(存储型/反射型/DOM型跨站脚本攻击)、原型污染、CSRF(跨站请求伪造) 业务逻辑缺陷 - 竞态条件、支付操纵、工作流程绕过 身份验证与会话 - JWT攻击、会话固定、凭证填充向量 基础设施与云 - 配置错误、暴露的服务、云安全问题 API安全 - 身份验证失效、批量赋值、速率限制绕过 代理图(多代理渗透测试) 先进的多代理编排,实现全面的自动化渗透测试: 分布式渗透测试 - 专门的人工智能代理用于侦察、利用和后利用 可扩展的安全测试 - 跨多个目标并行执行,实现快速、全面的覆盖 动态协调 - 代理共享发现结果、串联漏洞,并像红队一样协作 **用法示例** **基本用法** # Scan a local codebase strix --target ./app-directory # Security review of a GitHub repository strix --target https://github.com/org/repo # Black-box web application assessment strix --target https://your-app.com **高级测试场景** # Grey-box authenticated testing strix --target https://your-app.com --instruction "Perform authenticated testing using credentials: user:pass" # Multi-target testing (source code + deployed app) strix -t https://github.com/org/app -t https://your-app.com # White-box source-aware scan (local repository) strix --target ./app-directory --scan-mode standard # Focused testing with custom instructions strix --target api.your-app.com --instruction "Focus on business logic flaws and IDOR vulnerabilities" # Provide detailed instructions through file (e.g., rules of engagement, scope, exclusions) strix --target api.your-app.com --instruction-file ./instruction.md # Force PR diff-scope against a specific base branch strix -n --target ./ --scan-mode quick --scope-mode diff --diff-base origin/main 企业渗透测试 通过企业级控制获得相同的Strix体验:单点登录(SAML/OIDC)、符合定制合规要求的渗透测试报告(SOC 2、ISO 27001、PCI DSS)、专属支持与服务水平协议(SLA)、定制部署选项(VPC/自托管)、自带密钥(BYOK)模型支持,以及针对您的环境优化的定制化人工智能渗透测试代理。 项目地址:https://github.com/usestrix/strix

优秀的个人博客,低调大师

grep 半小时找不到 bug?亿级日志秒级定位的正确姿势

## **摘要**: 面对海量日志,传统的 grep 逐文件搜索方式效率低下且难以应对分布式环境。借助腾讯云 CLS 的倒排索引和 SQL 分析能力,可以在亿级数据量下实现秒级检索定位,大幅提升故障排查效率,让运维人员从繁琐的文本搜索中解放出来。 ## 一、为什么 grep 越来越不够用了 在 Linux 世界里,grep 是运维人员最熟悉的工具之一。`grep -r "error" /var/log/` 这样的命令几乎是每个工程师的肌肉记忆。当服务器只有一两台、日志文件数量有限时,grep 确实简单高效——打开终端、输入命令、几秒内就能看到结果。 然而随着业务规模扩大,这套方法的局限性日益明显。首先是数据量的问题。一个中等规模的电商系统每天可能产生数千万条日志,分布在几十台服务器的数百个日志文件中。当需要排查一个跨越多天的问题时,grep 需要逐文件扫描全部内容,耗时可能长达数十分钟甚至更久。如果多个工程师同时执行这类操作,还会对服务器的 I/O 和 CPU 造成额外压力。 其次是分布式环境的挑战。现代应用通常部署在多台服务器上,一次用户请求可能经过负载均衡器、API 网关、多个微服务和数据库。当这个请求出现问题时,相关日志分散在各个节点的独立文件中。运维人员需要先确定涉及哪些服务器,然后分别登录每台机器执行 grep,最后手动拼接出完整的调用链路。这个过程不仅耗时,还容易遗漏关键信息。 再者,grep 只能做简单的文本匹配,无法进行结构化分析。例如你想统计过去一小时各 API 接口的错误率分布,或者找出响应时间最长的 Top 10 请求,这些需求用 grep 配合 awk 虽然理论上可以实现,但编写复杂管道命令的成本很高,而且可读性和可维护性都很差。 最后是历史日志的可及性问题。为了节省磁盘空间,服务器上的日志通常会定期轮转和清理。当你需要回溯一周前的某个问题时,很可能发现相关日志已经被自动删除了。即使日志还在,从备份中恢复也是一个耗时的过程。 ## 二、倒排索引:秒级检索的核心原理 传统 grep 的工作方式是顺序扫描——从文件的第一个字节开始逐个比对,直到找到所有匹配项。这种方式的查询时间与日志总量成正比,数据量越大耗时越长。当面对亿级日志时,逐行扫描的效率瓶颈变得无法忽视。 CLS 实现秒级检索的关键在于倒排索引(Inverted Index)机制。它的核心思路是预先将日志内容按词项(Term)拆分并建立索引,记录每个词项出现在哪些日志行中。当用户搜索某个关键词时,系统直接查索引表就能获得匹配结果,无需扫描原始数据。 这就像查字典的过程:如果你想知道某本书里有没有出现过"事务超时"这个词,顺序扫描相当于从头到尾翻完整本书;而倒排索引相当于先给这本书做一个关键词索引,查询时直接翻到索引页即可。在 CLS 中,开启索引后日志写入时会同步构建倒排索引,后续检索直接命中索引结构,从而实现亿级数据量的秒级返回。 CLS 提供两种索引类型以适配不同场景:全文索引将日志内容按指定符号切分为多个分词并构建倒排索引,适用于自由文本的模糊搜索;键值索引则针对特定字段建立精确索引,适合结构化过滤和聚合分析。实际使用中两者搭配效果最佳——全文索引应对未知的排查需求,键值索引加速已知的字段筛选。需要注意的是,只有开启索引后的日志才能被检索分析,因此在接入 CLS 时应根据查询模式合理规划索引配置。 ## 三、从 grep 到 CLS 检索的实战对比 ### 3.1 基础关键词检索 假设你需要查找包含 "Connection timeout" 的所有日志行。在传统方式下,你可能需要这样操作: ``` # 在当前目录下递归搜索 grep -r "Connection timeout" /var/log/app/ ``` 如果日志分布在多台服务器上,还需要加上 SSH 跳转: ``` # 逐台服务器搜索 for server in web1 web2 web3; do ssh $server "grep 'Connection timeout' /var/log/app/*.log"; done ``` 而在 CLS 控制台上,只需在检索框中输入关键词即可: ``` Connection timeout ``` 系统会在所有接入的日志中进行全文检索,默认展示最近 15 分钟的匹配结果。如果需要调整时间范围,可以通过时间选择器快速切换。检索结果按时间倒序排列,最新的日志优先展示。 ### 3.2 组合条件过滤 实际排查中很少只用一个关键词。更多时候需要组合多个条件来缩小范围。例如查找过去一小时内来自特定 IP 的错误日志: ``` # grep 方式:复杂的管道组合 grep "ERROR" /var/log/app/*.log | grep "192.168.1.100" | grep "$(date -d '1 hour ago' '+%Y-%m-%d %H')" ``` 在 CLS 中,通过键值索引可以直接用结构化查询: ``` status:ERROR AND remote_addr:192.168.1.100 ``` 检索语法支持关键词、模糊和范围查询等多种模式。对于已经结构化的字段,可以使用 `field:value` 的格式进行精确匹配;对于文本内容,可以使用通配符进行模糊搜索;对于数值型字段,还可以用 `>`、`=`、`<=` 等运算符进行范围筛选。 ### 3.3 上下文查看与日志下载 grep 找到的结果通常是孤立的单行日志,缺乏上下文信息。要了解错误发生前后的完整情况,还需要再次打开日志文件查看相邻行。CLS 的检索结果支持上下文展开功能,点击任意一条日志即可查看其前后若干行的原始内容,帮助还原错误发生的完整场景。 对于需要离线分析的场景,CLS 支持日志下载功能。可以将检索结果导出为本地文件,方便进一步处理或作为事故报告的附件材料。 ## 四、SQL 分析:超越检索的深度洞察 检索只能帮你找到匹配的日志行,而 SQL 分析则可以回答更复杂的问题。当日志开启了索引后,就可以使用 SQL 语句对日志数据进行统计分析。 ### 4.1 错误趋势分析 与其手动统计每个小时的错误数量,不如用一条 SQL 直接生成趋势图: ``` SELECT HISTOGRAM(CAST(__time__ AS TIMESTAMP), INTERVAL 1 HOUR) AS dt, count(*) AS error_count FROM log WHERE level = 'ERROR' GROUP BY dt ORDER BY dt ``` 这条语句按小时粒度统计错误日志的数量变化,以折线图形式展示。通过观察趋势可以快速判断问题是持续存在还是间歇性出现,是逐渐恶化还是已经趋于平稳。 ### 4.2 Top N 聚合 找出最频繁出现的错误类型是定位根因的常见手段: ``` SELECT error_code, count(*) AS cnt FROM log WHERE level = 'ERROR' GROUP BY error_code ORDER BY cnt DESC LIMIT 10 ``` 这段 SQL 统计各错误码的出现频次并取 Top 10,帮助运维人员快速识别影响最大的问题类别。相比用 `grep | sort | uniq -c | sort -rn | head` 的组合命令,SQL 写法更加直观且易于维护。 ### 4.3 性能表现参考 根据 CLS 官方文档中的性能参考数据,CLS 在处理大规模数据时的表现如下:百亿级别日志的检索操作可在秒级返回;亿级日志的 SQL 分析秒级完成。这意味着即使面对海量日志数据,交互式分析也是完全可行的。 当然,实际查询速度会受到索引配置、查询复杂度、并发负载等因素的影响。对于特别复杂的分析需求,可以考虑使用定时 SQL 分析功能,将计算任务调度到系统负载较低的时段执行,避免影响交互式查询的体验。 ## 五、提升检索效率的实用技巧 ### 5.1 合理设计索引策略 并非所有日志都需要全文索引。对于主要以结构化字段为主的日志(如 JSON 格式的访问日志),重点为关键字段(如 status、method、url、user_id 等)配置键值索引即可获得很好的查询效果,同时减少不必要的索引开销。全文索引适合需要频繁进行自由文本搜索的场景,如应用运行日志中包含大量非结构化描述信息的情况。 ### 5.2 善用时间范围限定 日志数据具有强烈的时间局部性特征——大多数排查工作关注的是最近几分钟到几小时的数据。在执行检索时,尽量将时间范围限制在实际需要的区间内,避免无意义的全量扫描。这不仅加快了查询速度,也减少了资源消耗。 ### 5.3 利用仪表盘固化常用查询 对于日常高频使用的检索和分析查询,可以保存为仪表盘组件。这样下次需要查看时,直接打开仪表盘即可看到最新结果,无需重复编写查询语句。仪表盘还支持订阅功能,可以定期将图表快照推送到邮箱或企业微信,让团队成员都能及时了解系统状态。 想要体验 CLS 亿级日志秒级定位的能力,新用户开通即可领取 **10U × 3 个月** 免费资源包用于体验,首单特惠最低至 **0.8 折**起;新老用户购买资源包常规档位最低可享 **6.3 折**优惠。如需了解更多详情或领取优惠,可访问 [腾讯云 CLS 产品页](https://cloud.tencent.com/product/cls) 及 [特惠活动页](https://cloud.tencent.com/act/pro/cls_pu)。

优秀的个人博客,低调大师

deepwork v2026.06.16 发布,本次为基础框架升级和遗留 bug 修复版本

从 openclaw 开始,公司老板们经历了一场又一场的热潮,deepchat 也跟随升级为 deepwork,开始探索企业数字员工助手 本次更新: 1. yudao脚手架升级到2026.05 2. fix:模型对话响应格式部分丢失 3. fix:模型对话token使用量错误 4. fix:流程智能体配置页面无法打开 5. fix:后端聚合服务打包错误 6. fix:前端iconify及chat组件缺失导致打包失败

优秀的个人博客,低调大师

快速部署、排查Bug,向日葵远控CMD/SSH让开发更顺畅

每个程序员大概都懂那种场景——项目部署到服务器后,明明只是想改个配置、重启个进程,结果还得远程打开桌面,连界面加载都要等半天。尤其是服务器性能紧张时,远控桌面卡顿、加载慢、输入延迟,一次简单的操作就能浪费好几分钟。其实很多时候我们并不需要图形界面,只要能敲几行命令,就能高效解决问题。而这正是向日葵的CMD/SSH远程命令行功能最让人惊喜的地方。 在日常的运维或开发场景里,命令行往往比桌面更直接、更高效。向日葵的CMD/SSH功能,就是为这种高频操作而生的“效率神器”。无论是远程管理主机、部署应用,还是紧急排查问题,它都能帮你省下打开桌面的那几步,让每次远控操作更轻更快。 Windows用户:一键远控命令行,操作流畅 如果你是Windows用户,在向日葵设备列表中选中目标主机,点击「CMD」按钮,输入访问密码后,远程主机的命令行窗口就会直接弹出。整个过程几乎没有延迟,也不占用桌面资源。你可以像在本地一样执行任何命令,从系统管理到脚本运行,全程流畅。对于那些只需要执行服务重启、日志查看、环境变量修改等轻量级操作的开发者而言,这简直是生产力的加速键。 macOS/Linux用户:自动SSH模式,跨系统无障碍 而对于macOS或Linux用户,向日葵则会自动切换为「SSH」模式。只需登录系统账号,就能直接进入终端环境,进行所有命令行操作。无需繁琐设置,也不必安装额外的SSH客户端,跨系统的远程调试和管理就能轻松完成。需要注意的是,mac 用户在首次使用前,可以在「系统偏好设置 → 共享」中开启「远程登录」选项,以确保SSH连接顺畅。 安全保障:多重权限与访问控制 当然,安全性永远是远程控制中最重要的一环。向日葵在CMD/SSH连接中同样采用多重防护机制——每次连接都需要输入访问密码,系统账号权限也能精确控制。操作日志、连接记录清晰可追溯,既能保证调试安全,又能在团队协作时轻松实现权限分级。 以前遇到紧急问题,总得连上远控桌面,等界面加载、鼠标响应;现在只需点击CMD或SSH,命令行一开,几行指令下去,问题立刻解决。尤其在多主机环境下,能快速切换、批量操作,效率提升肉眼可见。 有时候,真正的高效不是多开几个窗口,而是少走几步操作。向日葵CMD/SSH功能,就是这样一个让程序员“事半功倍”的小细节——不用桌面,也能掌控全局。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册