Fix non-deterministic behavior in testMultipartFormData#649
Open
ZhanwangZhou wants to merge 1 commit intoNanoHttpd:masterfrom
Open
Fix non-deterministic behavior in testMultipartFormData#649ZhanwangZhou wants to merge 1 commit intoNanoHttpd:masterfrom
ZhanwangZhou wants to merge 1 commit intoNanoHttpd:masterfrom
Conversation
mahongyin
pushed a commit
to mahongyin/nanohttpd
that referenced
this pull request
Aug 7, 2025
MultipartFormData顺序问题 NanoHttpd/nanohttpd#633 升级commons-fileupload:commons-fileupload 1.3.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
I encountered non-deterministic behavior while running the following tests using NonDex:
core.src.test.java.org.nanohttpd.junit.protocols.http.HttpServerTest.testMultipartFormData
Steps to reproduce
NonDex: https://github.com/TestingResearchIllinois/NonDex
Run the tests with NonDex:
The error message shows:
Click to view
Potential Solution
The issue occurs due to non-deterministic behavior of function
public Response serve(IHTTPSession session)in testMultipartFormData. The function iterates through the key set ofMap<String, String>objectfilesand then appends the keys toStringBuilderobjectresponseMsg. However, the order of the key set of a Map object in Java is non-deterministic, which means the keys appended toresponseMsgcan be in any order. This causes theStringvariablelineat line 266 to be either"bincomment"or"commentbin", and thusassertEqualsat line 268 could fail.Here I propose a solution that may fix the issue. Before we iterate the key set of the map object, we can store all the keys in a
List<String>object and sort the list. Now, the order of keys in the list becomes deterministic, and we can iterate through the list and append the keys toresponseMsgin a deterministic order. In this way,linevariable will always be"bincomment", the same as the expected value.