← Lab /Software

New LLMs still misuse Java security APIs, but external security knowledge reduces errors

Even LLMs generate Java security API misuse, though retrieval-augmented security knowledge lowers the misuse rate in a model-dependent way

Software arXiv 29 May 2026 Replication Simulation evidence

Published as “R+R: Reassessing Java Security API Misuse in Current LLMs: A Replication on JCA and JSSE APIs with External Security Knowledge”

Why it matters

Integrating targeted security knowledge (especially code examples or misuse patterns) into LLM code generation pipelines can substantially lower API misuse, offering a practical path to safer AI-assisted development.

Summary

Even the newest frontier LLMs still generate insecure Java security API code, with GPT-5.5 showing a 36.60% misuse rate and Llama-3.3-70B-Instruct a 58.48% misuse rate under baseline prompting. Adding external security knowledge via retrieval-augmented generation or secure prompts cuts misuse roughly in half-down to 27.78% for Llama with Qwen-based RAG and to 17.74% for GPT-5.5 with a simple security prompt. The evidence comes from a replication of Mousavi et al.'s 48-task benchmark, running 30 samples per prompt (1080 total) and measuring compilable, correct-API, and misuse-free programs.

What they found 3

  1. Baseline GPT-5.5 produces 63.40% secure, misuse-free valid programs.

    “63.40% (646/1019) of them are valid programs with no detected misuse.”

  2. RAG with a Qwen dense retriever reduces Llama-3.3-70B-Instruct misuse rate to 27.78%.

    “reducing the misuse rate to 27.78% with Qwen embedding dense retriever”

  3. Providing only misuse-pattern knowledge eliminates the misuse segment for GPT-5.5.

    “Only misuse patterns produces the strongest overall result among the ablation conditions, with the valid-with-misuse segment disappearing”

Caveats 2

  • the misuse rate remains very high in symmetric encryption (F1), message authentication code (F6), key derivation (F7), SSL sockets (F10), hostname verification (F11), and certificate validation (F12)
  • We do not directly evaluate adversarial misuse-inducing instructions, but the observed sensitivity suggests that this is an important boundary condition for future work.

What’s new here 4

  • Evaluates much newer proprietary (GPT-5.5) and open-weight (Llama-3.3-70B-Instruct) models on the Java security API benchmark.
  • Introduces external security knowledge via Retrieval-Augmented Generation with multiple knowledge types (docs, guides, code examples, misuse patterns).
  • Performs knowledge-type ablation studies to identify which external information most reduces misuse.
  • Adds prompt-level perturbation stress tests (ignore-docs, keyword-steer) to probe the stability of retrieval gains.