JDBC remains a key technology for database access in Java applications. Since the database dictionary and the Java type system have distinct scopes, developers inevitably need to deal with bugs in SQL-to-Java type mappings. We propose an extension of the Java compiler, based on the established Checker Framework, which allows us to bridge this gap. Our approach verifies statically that the correct Java types are used when setting prepared statement parameters or when getting values from result sets. This allows us to lift a practically important class of runtime errors to compile time. Our approach is sound and, therefore, is guaranteed not to produce false negatives. Our prototype implementation also offers a degraded mode for type-checking legacy software, if developers are only interested in a subset of errors. Our experiments show that our approach detects a wide range of type mismatches in realworld application code and can indeed prevent errors which might otherwise surface as runtime errors. From the perspective of the developer, our approach is extremely lightweight: it processes the unmodified Java code, yet developers may add their own annotations. This allows us to perform type-checking even across method boundaries, whereas commercial developer tools are restricted to local checks. Finally, we show that we can type-check real-world JDBC software with reasonable overhead during compilation.


翻译:JDBC仍是Java应用中数据库访问的关键技术。由于数据库字典与Java类型系统具有不同的作用域,开发者不可避免地需要处理SQL与Java类型映射中的缺陷。我们提出一种基于成熟的Checker Framework对Java编译器进行扩展的方法,以弥合这一鸿沟。该方法能在编译时静态验证:设置预处理语句参数或从结果集获取值时,使用了正确的Java类型。这使得我们将实践中重要的一类运行时错误提升至编译阶段。我们的方法具有完备性,因此能保证不产生漏报。针对仅需关注部分错误的开发者,我们的原型实现还提供了用于类型检查遗留代码的降级模式。实验表明,该方法能检测出真实应用代码中广泛存在的类型不匹配问题,并有效预防可能以运行时错误形式暴露的缺陷。从开发者角度而言,该方法极为轻量:它可直接处理未经修改的Java代码,同时允许开发者添加自定义注解。这使得我们能够跨方法边界执行类型检查,而商业开发工具仅局限于局部检查。最后,我们证明该方法能在编译阶段以合理开销对真实JDBC软件进行类型检查。

0
下载
关闭预览

相关内容

Java 是一门编程语言,拥有跨平台、面向对象、泛型编程等特性。
数据库发展研究报告(2021年)
专知会员服务
50+阅读 · 2021年6月29日
基于MySQL Binlog的Elasticsearch数据同步实践
DBAplus社群
15+阅读 · 2019年9月3日
使用 Bert 预训练模型文本分类(内附源码)
数据库开发
102+阅读 · 2019年3月12日
使用 Canal 实现数据异构
性能与架构
20+阅读 · 2019年3月4日
统计学常用数据类型
论智
19+阅读 · 2018年7月6日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
13+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Arxiv
0+阅读 · 4月22日
VIP会员
最新内容
ICML 2026 | Sheaf-ADMM:用可微优化学习多智能体协调
专知会员服务
1+阅读 · 今天16:12
综述 | OPSD:大语言模型的在线策略自蒸馏
专知会员服务
1+阅读 · 今天16:08
算法化战争:人工智能时代的新范式(万字长文)
帕兰蒂尔Maven:军事人工智能的新纪元
专知会员服务
3+阅读 · 今天14:00
超越网格:作战环境对炮兵的影响
专知会员服务
3+阅读 · 5月31日
BES:让语言模型通过双向进化搜索自我改进
专知会员服务
6+阅读 · 5月30日
以色列-美国-伊朗战争中的无人机:关键要点
专知会员服务
7+阅读 · 5月30日
相关VIP内容
数据库发展研究报告(2021年)
专知会员服务
50+阅读 · 2021年6月29日
相关基金
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
13+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员