Skip to content

Because the Method [] getDeclaredMethods method returns a non fixed order list, instability occurs in all places where index is used in the program (this project only has it in testing) #6

@TheEterna

Description

@TheEterna

During testing, there may be occasional failures and occasional successes. The code is as follows:

@Test
	void testGetLoggingConsumers() {
		LoggingHandler loggingHandler = new LoggingHandler();
		SyncMcpLoggingConsumerProvider provider = new SyncMcpLoggingConsumerProvider(List.of(loggingHandler));

		// Hava a bug: bean. getClass(). getDeclaredMethods() in the doGetClassMethods method called in provider. getLoggingConsumers(), the order of the returned method list is not fixed, so values cannot be obtained through index
		List<Consumer<LoggingMessageNotification>> consumers = provider.getLoggingConsumers();
		// Sort consumers by method name to ensure stable ordering

		// Should find 2 annotated methods
		assertThat(consumers).hasSize(2);

		// Test the first consumer
		LoggingMessageNotification notification = new LoggingMessageNotification(LoggingLevel.INFO, "test-logger", "This is a test message");

		consumers.get(0).accept(notification);

		// Verify that the method was called
		assertThat(loggingHandler.lastNotification).isEqualTo(notification);

		// Test the second consumer
		consumers.get(1).accept(notification);

		// Verify that the method was called
		assertThat(loggingHandler.lastLevel).isEqualTo(notification.level());
		assertThat(loggingHandler.lastLogger).isEqualTo(notification.logger());
		assertThat(loggingHandler.lastData).isEqualTo(notification.data());
	}

Reason for bug: bean. getClass(). getDeclaredMethods() in the doGetClassMethods method called in provider. getLoggingConsumers(), the order of the returned method list is not fixed, so values cannot be obtained through index

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions