muttakin2301/ccr2000 huggingface dataset:
Code review comment: Just to confirm, this will include compile-only, runtime and quarkusDev scopes?

Code under review:
private static Configuration classpathConfig(Project project, LaunchMode mode) {
        if (LaunchMode.TEST.equals(mode)) {
            return project.getConfigurations().getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
        }
        if (LaunchMode.DEVELOPMENT.equals(mode)) {
            Configuration classpathConfiguration = project.getConfigurations().findByName(CLASSPATH_CONFIGURATION);
            if (classpathConfiguration != null) {
                project.getConfigurations().remove(classpathConfiguration);
            }

            return project.getConfigurations().create(CLASSPATH_CONFIGURATION).extendsFrom(
                    project.getConfigurations().getByName(QuarkusPlugin.DEV_MODE_CONFIGURATION_NAME),
                    project.getConfigurations().getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME));
        }
        return project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
    }

Line commented on: project.getConfigurations().getByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME));

Revised code:
private static Configuration classpathConfig(Project project, LaunchMode mode) {
        if (LaunchMode.TEST.equals(mode)) {
            return project.getConfigurations().getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
        }
        if (LaunchMode.DEVELOPMENT.equals(mode)) {
            Configuration classpathConfiguration = project.getConfigurations().findByName(CLASSPATH_CONFIGURATION);
            if (classpathConfiguration != null) {
                project.getConfigurations().remove(classpathConfiguration);
            }

            return project.getConfigurations().create(CLASSPATH_CONFIGURATION).extendsFrom(
                    project.getConfigurations().getByName(QuarkusPlugin.DEV_MODE_CONFIGURATION_NAME),
                    project.getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME),
                    project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
        }
        return project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
    }
Code review comment: I'm not familiar with the logic here, but it looks like you're retrying up to the maximum number of times, even if it was successful before then.

Code under review:
private void reSetupBdbEnvironment(InsufficientLogException insufficientLogEx) {
        LOG.warn("catch insufficient log exception. will recover and try again.", insufficientLogEx);
        
        
        
        
        HostInfo helperNode = Env.getServingEnv().getHelperNode();

        for (int i = 0; i < RETRY_TIME; i++) {
            try {
                NetworkRestore restore = new NetworkRestore();
                NetworkRestoreConfig config = new NetworkRestoreConfig();
                config.setRetainLogFiles(false);
                restore.execute(insufficientLogEx, config);
            } catch (Exception e) {
                LOG.warn("retry={}, reSetupBdbEnvironment exception:", i, e);
                try {
                    Thread.sleep(5 * 1000);
                    LOG.warn("after sleep insufficientLogEx:", insufficientLogEx);
                } catch (InterruptedException e1) {
                    LOG.warn("InterruptedException", e1);
                }
            }
        }

        bdbEnvironment.close();
        bdbEnvironment.setup(new File(environmentPath), selfNodeName, selfNodeHostPort,
                helperNode.getIp() + ":" + helperNode.getPort(), Env.getServingEnv().isElectable());
    }

Line commented on: restore.execute(insufficientLogEx, config);

Revised code:
private void reSetupBdbEnvironment(InsufficientLogException insufficientLogEx) {
        LOG.warn("catch insufficient log exception. will recover and try again.", insufficientLogEx);
        
        
        
        
        HostInfo helperNode = Env.getServingEnv().getHelperNode();

        for (int i = 0; i < RETRY_TIME; i++) {
            try {
                NetworkRestore restore = new NetworkRestore();
                NetworkRestoreConfig config = new NetworkRestoreConfig();
                config.setRetainLogFiles(false);
                restore.execute(insufficientLogEx, config);
                break;
            } catch (Exception e) {
                LOG.warn("retry={}, reSetupBdbEnvironment exception:", i, e);
                try {
                    Thread.sleep(5 * 1000);
                    LOG.warn("after sleep insufficientLogEx:", insufficientLogEx);
                } catch (InterruptedException e1) {
                    LOG.warn("InterruptedException", e1);
                }
            }
        }

        bdbEnvironment.close();
        bdbEnvironment.setup(new File(environmentPath), selfNodeName, selfNodeHostPort,
                helperNode.getIp() + ":" + helperNode.getPort(), Env.getServingEnv().isElectable());
    }
Code review comment: You either filter it or you attempt to re-add those that you already went over, which is harmless anyway.

Code under review:
private static ScopeInfo initStereotypeScope(List<StereotypeInfo> stereotypes, AnnotationTarget target) {
        if (stereotypes.isEmpty()) {
            return null;
        }
        
        Set<ScopeInfo> stereotypeScopes = stereotypes.stream().filter(s -> !s.isAdditionalBeanDefiningAnnotation())
                .map(stereotypeInfo -> stereotypeInfo.getDefaultScope())
                .collect(Collectors.toSet());
        
        if (stereotypeScopes.isEmpty()) {
            stereotypeScopes.addAll(stereotypes.stream().filter(s -> s.isAdditionalBeanDefiningAnnotation())
                    .map(si -> si.getDefaultScope())
                    .collect(Collectors.toSet()));
        }
        return BeanDeployment.getValidScope(stereotypeScopes, target);
    }

Line commented on: stereotypeScopes.addAll(stereotypes.stream().filter(s -> s.isAdditionalBeanDefiningAnnotation())

Revised code:
private static ScopeInfo initStereotypeScope(List<StereotypeInfo> stereotypes, AnnotationTarget target) {
        if (stereotypes.isEmpty()) {
            return null;
        }
        final Set<ScopeInfo> stereotypeScopes = new HashSet<>();
        final Set<ScopeInfo> additionalBDAScopes = new HashSet<>();
        for (StereotypeInfo stereotype : stereotypes) {
            if (!stereotype.isAdditionalBeanDefiningAnnotation()) {
                stereotypeScopes.add(stereotype.getDefaultScope());
            } else {
                additionalBDAScopes.add(stereotype.getDefaultScope());
            }
        }
        
        return BeanDeployment.getValidScope(stereotypeScopes.isEmpty() ? additionalBDAScopes : stereotypeScopes, target);
    }
Code review comment: Same validation here as well. https://github.com/ballerina-platform/ballerina-lang/pull/18233/files#r318003438

Code under review:
public boolean equals(Object obj) {
        if (!(obj instanceof BDiagnosticSource)) {
            return false;
        }
        BDiagnosticSource diagnosticSource = (BDiagnosticSource) obj;
        return pkgID.equals(diagnosticSource.pkgID) && cUnitName.equals(diagnosticSource.cUnitName);
    }

Line commented on: if (!(obj instanceof BDiagnosticSource)) {

Revised code:
public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof BDiagnosticSource)) {
            return false;
        }
        BDiagnosticSource diagnosticSource = (BDiagnosticSource) obj;
        return pkgID.equals(diagnosticSource.pkgID) && cUnitName.equals(diagnosticSource.cUnitName);
    }
Code review comment: It looks like the new IT doesn't pass: https://builds.apache.org/job/beam_PostCommit_Java_PR/169/testReport/junit/org.apache.beam.sdk.io.gcp.pubsub/PubsubReadIT/testReadPubsubMessageId/

Code under review:
public void testReadPubsubMessageId() throws Exception {
    
    pipeline.getOptions().as(DirectOptions.class).setBlockOnRun(false);

    PCollection<PubsubMessage> messages =
        pipeline.apply(
            PubsubIO.readMessagesWithMessageId()
                .fromTopic("projects/pubsub-public-data/topics/taxirides-realtime"));

    messages.apply(
        "isMessageIdNonNull",
        signal.signalSuccessWhen(
            messages.getCoder(),
            pubsubMessages ->
                pubsubMessages.stream().noneMatch(m -> Strings.isNullOrEmpty(m.getMessageId()))));

    Supplier<Void> start = signal.waitForStart(Duration.standardMinutes(5));
    pipeline.apply(signal.signalStart());
    PipelineResult job = pipeline.run();
    start.get();

    signal.waitForSuccess(Duration.standardSeconds(30));
    
    try {
      job.cancel();
    } catch (UnsupportedOperationException exc) {
      
    }
  }

Line commented on: pubsubMessages.stream().noneMatch(m -> Strings.isNullOrEmpty(m.getMessageId()))));

Revised code:
public void testReadPubsubMessageId() throws Exception {
    
    pipeline.getOptions().as(DirectOptions.class).setBlockOnRun(false);

    PCollection<PubsubMessage> messages =
        pipeline.apply(
            PubsubIO.readMessagesWithAttributesAndMessageId()
                .fromTopic("projects/pubsub-public-data/topics/taxirides-realtime"));

    messages.apply(
        "isMessageIdNonNull",
        signal.signalSuccessWhen(messages.getCoder(), new NonEmptyMessageIdCheck()));

    Supplier<Void> start = signal.waitForStart(Duration.standardMinutes(5));
    pipeline.apply(signal.signalStart());
    PipelineResult job = pipeline.run();
    start.get();

    signal.waitForSuccess(Duration.standardMinutes(1));
    
    try {
      job.cancel();
    } catch (UnsupportedOperationException exc) {
      
    }
  }
Code review comment: Yeah, `convertibleTypes.size() < 2` is kind of repeated check, that is not needed here. But we need to preserve the `convertibleTypes.size()  == 0` check for other places. Moved that check to outside of this method.  Addressed with https://github.com/ballerina-platform/ballerina-lang/pull/30710/commits/688ab907b7244cd39e24c251849c329e7f7fbe24

Code under review:
public static boolean hasIntegerSubTypes(Set<Type> convertibleTypes) {
        if (convertibleTypes.size() < 2) {
            return false;
        }
        for (Type type : convertibleTypes) {
            if (!TypeTags.isIntegerTypeTag(type.getTag()) && type.getTag() != TypeTags.BYTE_TAG) {
                return false;
            }
        }
        return true;
    }

Line commented on: if (convertibleTypes.size() < 2) {

Revised code:
public static boolean hasIntegerSubTypes(Set<Type> convertibleTypes) {
        for (Type type : convertibleTypes) {
            if (!TypeTags.isIntegerTypeTag(type.getTag()) && type.getTag() != TypeTags.BYTE_TAG) {
                return false;
            }
        }
        return true;
    }
Code review comment: It would submit a thread to do this job

Code under review:
public AnalysisTaskExecutor(int simultaneouslyRunningTaskNum) {
        if (!Env.isCheckpointThread()) {
            executors = ThreadPoolManager.newDaemonThreadPool(
                    simultaneouslyRunningTaskNum,
                    simultaneouslyRunningTaskNum, 0,
                    TimeUnit.DAYS, new LinkedBlockingQueue<>(),
                    new BlockedPolicy("Analysis Job Executor", Integer.MAX_VALUE),
                    "Analysis Job Executor", true);
            cancelExpiredTask();
        } else {
            executors = null;
        }
    }

Line commented on: cancelExpiredTask();

Revised code:
public AnalysisTaskExecutor(int simultaneouslyRunningTaskNum) {
        if (!Env.isCheckpointThread()) {
            executors = ThreadPoolManager.newDaemonThreadPool(
                    simultaneouslyRunningTaskNum,
                    simultaneouslyRunningTaskNum, 0,
                    TimeUnit.DAYS, new LinkedBlockingQueue<>(),
                    new BlockedPolicy("Analysis Job Executor", Integer.MAX_VALUE),
                    "Analysis Job Executor", true);
            cancelExpiredTask();
        } else {
            executors = null;
        }
    }
Code review comment: Shall we make it as single line statement?

Code under review:
public WebSocketService(Service service) {
        this.service = service;
        for (Resource resource : service.getResources()) {
            resourceMap.put(resource.getName(), resource);
        }

        Annotation configAnnotation =
                WebSocketUtil.getServiceConfigAnnotation(service);

        Struct configAnnotationStruct = null;
        if (configAnnotation != null && (configAnnotationStruct = configAnnotation.getValue()) != null) {
            negotiableSubProtocols = findNegotiableSubProtocols(configAnnotationStruct);
            idleTimeoutInSeconds = findIdleTimeoutInSeconds(configAnnotationStruct);
            maxFrameSize = findMaxFrameSize(configAnnotationStruct);
        }
        if (WebSocketConstants.WEBSOCKET_ENDPOINT_NAME.equals(service.getEndpointName())) {
            basePath = findFullWebSocketUpgradePath(configAnnotationStruct);
        }

    }

Line commented on: Annotation configAnnotation =

Revised code:
public WebSocketService(Service service) {
        this.service = service;
        for (Resource resource : service.getResources()) {
            resourceMap.put(resource.getName(), resource);
        }

        Annotation configAnnotation = WebSocketUtil.getServiceConfigAnnotation(service);

        Struct configAnnotationStruct = null;
        if (configAnnotation != null && (configAnnotationStruct = configAnnotation.getValue()) != null) {
            negotiableSubProtocols = findNegotiableSubProtocols(configAnnotationStruct);
            idleTimeoutInSeconds = findIdleTimeoutInSeconds(configAnnotationStruct);
            maxFrameSize = findMaxFrameSize(configAnnotationStruct);
        }
        if (WebSocketConstants.WEBSOCKET_ENDPOINT_NAME.equals(service.getEndpointName())) {
            basePath = findFullWebSocketUpgradePath(configAnnotationStruct);
        }

    }
Code review comment: yeah I'd revisit it once junit5 is in.

Code under review:
private static void randomize(Configuration conf) {
        if (Randomization) {
            final String testName = TestNameProvider.getCurrentTestName();
            final PseudoRandomValueSelector valueSelector =
                    PseudoRandomValueSelector.create(testName != null ? testName : "unknown");
            valueSelector.select(conf, ExecutionCheckpointingOptions.ENABLE_UNALIGNED, true, false);
        }
    }

Line commented on: PseudoRandomValueSelector.create(testName != null ? testName : "unknown");

Revised code:
private static void randomize(Configuration conf) {
        if (RANDOMIZE_CHECKPOINTING_CONFIG) {
            final String testName = TestNameProvider.getCurrentTestName();
            final PseudoRandomValueSelector valueSelector =
                    PseudoRandomValueSelector.create(testName != null ? testName : "unknown");
            valueSelector.select(conf, ExecutionCheckpointingOptions.ENABLE_UNALIGNED, true, false);
        }
    }
Code review comment: One small question, is this the standard way of adding "`"?  I couldn't find the relevant documents.

Code under review:
public void testNestedFilterWithBacktickInTheName() {
        util.verifyRelPlan(
                "SELECT id FROM NestedTable WHERE `deepNestedWith.`.nested.```name` = 'foo'");
    }

Line commented on: "SELECT id FROM NestedTable WHERE `deepNestedWith.`.nested.```name` = 'foo'");

Revised code:
public void testNestedFilterWithBacktickInTheName() {
        util.verifyRelPlan(
                "SELECT id FROM NestedTable WHERE `deepNestedWith.`.nested.```name` = 'foo'");
    }
Code review comment: This would cause NPE given that we remove `jobVertexID` from `tasksReachedEndOfData` after all its subtasks have finished.  Also, given that `areAllTasksOfJobVertexEndOfData()` is currently invoked after `areAllTasksEndOfData()`, it suggests that this code path is not tested. Can you add a test for this scenario?

Code under review:
public boolean areAllTasksOfJobVertexEndOfData(JobVertexID jobVertexID) {
        BitSet subtaskStatus = tasksReachedEndOfData.get(jobVertexID);
        return subtaskStatus.cardinality()
                == executionGraph.getJobVertex(jobVertexID).getParallelism();
    }

Line commented on: return subtaskStatus.cardinality()

Revised code:
public boolean areAllTasksOfJobVertexEndOfData(JobVertexID jobVertexID) {
        BitSet subtaskStatus = tasksReachedEndOfData.get(jobVertexID);
        return subtaskStatus == null
                || subtaskStatus.cardinality()
                        == executionGraph.getJobVertex(jobVertexID).getParallelism();
    }
Code review comment: The purpose of this `TODO` is to avoid conflict between `workerResourceSpec` and `process.size`/`flink.size` in `flinkConfig`. It is not about forbidden workers with different sizes. Actually, one of the main purpose of this PR is to make the RMs not assuming workers have the same size.  I was thinking about change the `Configuration` at creating the `SlotManager`, where we known which implementation of `SlotManager` is used and unset flink/process size if the plugin supports dynamic worker sizes.

Code under review:
private KubernetesTaskManagerParameters createKubernetesTaskManagerParameters(WorkerResourceSpec workerResourceSpec) {
		
		final TaskExecutorProcessSpec taskExecutorProcessSpec =
			TaskExecutorProcessUtils.processSpecFromWorkerResourceSpec(flinkConfig, workerResourceSpec);

		final String podName = String.format(
			TASK_MANAGER_POD_FORMAT,
			clusterId,
			currentMaxAttemptId,
			++currentMaxPodId);

		final ContaineredTaskManagerParameters taskManagerParameters =
			ContaineredTaskManagerParameters.create(flinkConfig, taskExecutorProcessSpec);

		final String dynamicProperties =
			BootstrapTools.getDynamicPropertiesAsString(flinkClientConfig, flinkConfig);

		return new KubernetesTaskManagerParameters(
			flinkConfig,
			podName,
			dynamicProperties,
			taskManagerParameters);
	}


Revised code:
private KubernetesTaskManagerParameters createKubernetesTaskManagerParameters(WorkerResourceSpec workerResourceSpec) {
		final TaskExecutorProcessSpec taskExecutorProcessSpec =
			TaskExecutorProcessUtils.processSpecFromWorkerResourceSpec(flinkConfig, workerResourceSpec);

		final String podName = String.format(
			TASK_MANAGER_POD_FORMAT,
			clusterId,
			currentMaxAttemptId,
			++currentMaxPodId);

		final ContaineredTaskManagerParameters taskManagerParameters =
			ContaineredTaskManagerParameters.create(flinkConfig, taskExecutorProcessSpec);

		final String dynamicProperties =
			BootstrapTools.getDynamicPropertiesAsString(flinkClientConfig, flinkConfig);

		return new KubernetesTaskManagerParameters(
			flinkConfig,
			podName,
			dynamicProperties,
			taskManagerParameters);
	}
Code review comment: `env.node.parent` was replaced with `env.enclInvokable`

Code under review:
private void resolveAssociatedWorkerFunc(BWorkerSymbol worker, SymbolEnv env) {
        LineRange workerVarPos = worker.pos.lineRange();

        for (BLangLambdaFunction lambdaFn : env.enclPkg.lambdaFunctions) {
            LineRange workerBodyPos = lambdaFn.function.pos.lineRange();
            Location targetRangePos = env.node.pos;

            
            
            
            if (targetRangePos == null) {
                targetRangePos = env.node.parent.pos;
            }

            if (worker.name.value.equals(lambdaFn.function.defaultWorkerName.value)
                    && withinRange(workerVarPos, targetRangePos.lineRange())
                    && withinRange(workerBodyPos, targetRangePos.lineRange())) {
                worker.setAssociatedFuncSymbol(lambdaFn.function.symbol);
                return;
            }
        }

        throw new IllegalStateException(
                "Matching function node not found for worker: " + worker.name.value + " at " + worker.pos);
    }

Line commented on: if (targetRangePos == null) {

Revised code:
private void resolveAssociatedWorkerFunc(BWorkerSymbol worker, SymbolEnv env) {
        LineRange workerVarPos = worker.pos.lineRange();

        for (BLangLambdaFunction lambdaFn : env.enclPkg.lambdaFunctions) {
            LineRange workerBodyPos = lambdaFn.function.pos.lineRange();
            Location targetRangePos = env.node.pos;

            
            
            
            if (targetRangePos == null) {
                targetRangePos = env.enclInvokable.pos;
            }

            if (worker.name.value.equals(lambdaFn.function.defaultWorkerName.value)
                    && withinRange(workerVarPos, targetRangePos.lineRange())
                    && withinRange(workerBodyPos, targetRangePos.lineRange())) {
                worker.setAssociatedFuncSymbol(lambdaFn.function.symbol);
                return;
            }
        }

        throw new IllegalStateException(
                "Matching function node not found for worker: " + worker.name.value + " at " + worker.pos);
    }
Code review comment: Great point, adding an individual `try-catch` block.

Code under review:
public void shutdown() throws Exception {
        Throwable firstException = null;

        try {
            futureExecutor.shutdownNow();
            ioExecutor.shutdownNow();
        } catch (Throwable t) {
            firstException = t;
        }

        try {
            shuffleMaster.close();
        } catch (Throwable t) {
            firstException = firstException == null ? t : firstException;
        }

        libraryCacheManager.shutdown();

        if (firstException != null) {
            ExceptionUtils.rethrowException(
                    firstException, "Error while shutting down JobManager services");
        }
    }

Line commented on: ioExecutor.shutdownNow();

Revised code:
public void shutdown() throws Exception {
        Throwable exception = null;

        try {
            ExecutorUtils.gracefulShutdown(
                    SHUTDOWN_TIMEOUT.toMillis(), TimeUnit.MILLISECONDS, futureExecutor, ioExecutor);
        } catch (Throwable t) {
            exception = t;
        }

        try {
            shuffleMaster.close();
        } catch (Throwable t) {
            exception = ExceptionUtils.firstOrSuppressed(t, exception);
        }

        libraryCacheManager.shutdown();

        if (exception != null) {
            ExceptionUtils.rethrowException(
                    exception, "Error while shutting down JobManager services");
        }
    }
Code review comment: We don't have anywhere that is specifically dedicated to testing RESTEasy + Undertow, so I just enhanced the security tests to also test RESTEasy on Undertow, but used this mechanism to map RESTeasy.

Code under review:
void testPost() {
        
        
        
        given()
                .header("Authorization", "Basic am9objpqb2hu")
                .body("Bill")
                .contentType(ContentType.TEXT)
                .when()
                .post("/foo/mapped/rest")
                .then()
                .statusCode(200)
                .body(is("post success"));
    }


Revised code:
void testPost() {
        
        
        
        given()
                .header("Authorization", "Basic am9objpqb2hu")
                .body("Bill")
                .contentType(ContentType.TEXT)
                .when()
                .post("/foo/mapped/rest")
                .then()
                .statusCode(200)
                .body(is("post success"));
    }
Code review comment: @hemikak WDYT of using `anyMatch(predicate)` instead? IMO it'll be more convenient for the above context, if we don't need the exact count.

Code under review:
public static CompileResult compile(String sourceFilePath) {
        Path sourcePath = Paths.get(sourceFilePath);
        String sourceFileName = sourcePath.getFileName().toString();
        Path sourceRoot = testSourcesDirectory.resolve(sourcePath.getParent());

        Path projectPath = Paths.get(sourceRoot.toString(), sourceFileName);
        Project project = ProjectLoader.loadProject(projectPath);

        Package currentPackage = project.currentPackage();
        PackageCompilation packageCompilation = currentPackage.getCompilation();
        JBallerinaBackend jBallerinaBackend = JBallerinaBackend.from(packageCompilation, JdkVersion.JAVA_11);
        long errorCount = jBallerinaBackend.diagnostics().stream().filter(diagnostic ->
                diagnostic.diagnosticInfo().severity() == DiagnosticSeverity.ERROR).count();
        if (errorCount > 0) {
            return new CompileResult(currentPackage, jBallerinaBackend.diagnostics());
        }

        Path jarTargetPath = jarTargetPath(currentPackage);
        jBallerinaBackend.emit(JBallerinaBackend.OutputType.JAR, jarTargetPath);

        CompileResult compileResult = new CompileResult(currentPackage, jBallerinaBackend.diagnostics(), jarTargetPath);
        invokeModuleInit(compileResult);
        return compileResult;
    }

Line commented on: long errorCount = jBallerinaBackend.diagnostics().stream().filter(diagnostic ->

Revised code:
public static CompileResult compile(String sourceFilePath) {
        Path sourcePath = Paths.get(sourceFilePath);
        String sourceFileName = sourcePath.getFileName().toString();
        Path sourceRoot = testSourcesDirectory.resolve(sourcePath.getParent());

        Path projectPath = Paths.get(sourceRoot.toString(), sourceFileName);
        Project project = ProjectLoader.loadProject(projectPath);

        Package currentPackage = project.currentPackage();
        PackageCompilation packageCompilation = currentPackage.getCompilation();
        JBallerinaBackend jBallerinaBackend = JBallerinaBackend.from(packageCompilation, JdkVersion.JAVA_11);
        boolean containErrors = jBallerinaBackend.diagnostics().stream()
                .anyMatch(diagnostic -> diagnostic.diagnosticInfo().severity() == DiagnosticSeverity.ERROR);
        if (containErrors) {
            return new CompileResult(currentPackage, jBallerinaBackend.diagnostics());
        }

        Path jarTargetPath = jarTargetPath(currentPackage);
        jBallerinaBackend.emit(JBallerinaBackend.OutputType.JAR, jarTargetPath);

        CompileResult compileResult = new CompileResult(currentPackage, jBallerinaBackend.diagnostics(), jarTargetPath);
        invokeModuleInit(compileResult);
        return compileResult;
    }
Code review comment: Shouldn't this be an AND expression here? Since both the `namespacePrefix` and the `asKeyword` should not be null.

Code under review:
public XMLNamespaceDeclarationNode transform(XMLNamespaceDeclarationNode xMLNamespaceDeclarationNode) {
        Token xmlnsKeyword = getToken(xMLNamespaceDeclarationNode.xmlnsKeyword());
        ExpressionNode namespaceuri = this.modifyNode(xMLNamespaceDeclarationNode.namespaceuri());
        Token asKeyword = getToken(xMLNamespaceDeclarationNode.asKeyword().orElse(null));
        IdentifierToken namespacePrefix = this.modifyNode(xMLNamespaceDeclarationNode.namespacePrefix().orElse(null));
        Token semicolonToken = getToken(xMLNamespaceDeclarationNode.semicolonToken());
        if (asKeyword != null || namespacePrefix != null) {
            xMLNamespaceDeclarationNode = xMLNamespaceDeclarationNode.modify()
                    .withNamespacePrefix(namespacePrefix)
                    .withAsKeyword(formatToken(asKeyword, 1, 1, 0, 0))
                    .apply();
        }
        return xMLNamespaceDeclarationNode.modify()
                .withNamespaceuri(namespaceuri)
                .withXmlnsKeyword(formatToken(xmlnsKeyword, 3, 1, 0, 0))
                .withSemicolonToken(formatToken(semicolonToken, 0, 0, 0, 1))
                .apply();
    }

Line commented on: if (asKeyword != null || namespacePrefix != null) {

Revised code:
public XMLNamespaceDeclarationNode transform(XMLNamespaceDeclarationNode xMLNamespaceDeclarationNode) {
        Token xmlnsKeyword = getToken(xMLNamespaceDeclarationNode.xmlnsKeyword());
        ExpressionNode namespaceuri = this.modifyNode(xMLNamespaceDeclarationNode.namespaceuri());
        Token asKeyword = getToken(xMLNamespaceDeclarationNode.asKeyword().orElse(null));
        IdentifierToken namespacePrefix = this.modifyNode(xMLNamespaceDeclarationNode.namespacePrefix().orElse(null));
        Token semicolonToken = getToken(xMLNamespaceDeclarationNode.semicolonToken());
        int startColumn = getStartColumn(xMLNamespaceDeclarationNode, xMLNamespaceDeclarationNode.kind(), true);

        if (asKeyword != null) {
            xMLNamespaceDeclarationNode = xMLNamespaceDeclarationNode.modify()
                    .withAsKeyword(formatToken(asKeyword, 1, 1, 0, 0))
                    .apply();
        }
        if (namespacePrefix != null) {
            xMLNamespaceDeclarationNode = xMLNamespaceDeclarationNode.modify()
                    .withNamespacePrefix(namespacePrefix)
                    .apply();
        }

        return xMLNamespaceDeclarationNode.modify()
                .withNamespaceuri(namespaceuri)
                .withXmlnsKeyword(formatToken(xmlnsKeyword, startColumn, 1, 0, 0))
                .withSemicolonToken(formatToken(semicolonToken, 0, 0, 0, 1))
                .apply();
    }
Code review comment: Why use `AtomicBoolean`? Does some race conditions exist?

Code under review:
private LogicalPlan replaceSortExpression(LogicalSort<? extends LogicalPlan> sort, Map<Expression, Slot> sMap) {
        List<OrderKey> orderKeys = sort.getOrderKeys();
        AtomicBoolean changed = new AtomicBoolean(false);
        List<OrderKey> newKeys = orderKeys.stream().map(k -> {
            Expression newExpr = ExpressionUtils.replace(k.getExpr(), sMap);
            if (newExpr != k.getExpr()) {
                changed.set(true);
            }
            return new OrderKey(newExpr, k.isAsc(), k.isNullFirst());
        }).collect(Collectors.toList());
        if (changed.get()) {
            return new LogicalSort<>(newKeys, sort.child());
        } else {
            return sort;
        }
    }

Line commented on: AtomicBoolean changed = new AtomicBoolean(false);

Revised code:
private LogicalPlan replaceSortExpression(LogicalSort<? extends LogicalPlan> sort, Map<Expression, Slot> sMap) {
        List<OrderKey> orderKeys = sort.getOrderKeys();
        AtomicBoolean changed = new AtomicBoolean(false);
        List<OrderKey> newKeys = orderKeys.stream().map(k -> {
            Expression newExpr = ExpressionUtils.replace(k.getExpr(), sMap);
            if (newExpr != k.getExpr()) {
                changed.set(true);
            }
            return new OrderKey(newExpr, k.isAsc(), k.isNullFirst());
        }).collect(Collectors.toList());
        if (changed.get()) {
            return new LogicalSort<>(newKeys, sort.child());
        } else {
            return sort;
        }
    }
Code review comment: Is this guaranteed to be non-null and non-empty?

Code under review:
private String getPotentialSetterName() {
            String fieldName = declaringField.getName();

            return "set" + fieldName.substring(0, 1).toUpperCase(Locale.ROOT) + fieldName.substring(1);
        }

Line commented on: String fieldName = declaringField.getName();

Revised code:
private String getPotentialSetterName() {
            String fieldName = declaringField.getName();

            return "set" + fieldName.substring(0, 1).toUpperCase(Locale.ROOT) + fieldName.substring(1);
        }
Code review comment: That's a good question. Maybe we should use `org.quartz.Scheduler.isInStandbyMode()` but in that case we should modify the behavior of `QuartzScheduler.pause()` and `QuartzScheduler.resume()`. Currently, we call `pauseAll()/resumeAll()` but we should probably call `standby()/start()` instead. @machi1990 WDYT?

Code under review:
public void testNoSchedulerInvocations() throws InterruptedException {
        
        assertFalse(Jobs.LATCH.await(5, TimeUnit.SECONDS));
    }

Line commented on: assertFalse(Jobs.LATCH.await(5, TimeUnit.SECONDS));

Revised code:
public void testNoSchedulerInvocations() throws InterruptedException {
        assertFalse(quartzScheduler.isRunning());
    }
Code review comment: We should use Junit5 `assertThat(xxx).isEqualTo()` clause.

Code under review:
public void testAdapt() throws Exception {
        KeyedStateBackend<Integer> keyedStateBackend = new TestKeyedStateBackend();
        AsyncKeyedStateBackendAdaptor<Integer> adaptor =
                new AsyncKeyedStateBackendAdaptor(keyedStateBackend);
        StateDescriptor descriptor =
                new ValueStateDescriptor<>("testState", BasicTypeInfo.INT_TYPE_INFO);

        org.apache.flink.api.common.state.v2.ValueState<Integer> valueState =
                (org.apache.flink.api.common.state.v2.ValueState<Integer>)
                        adaptor.createState(null, null, descriptor);

        
        valueState.clear();
        valueState.update(10);
        assertEquals(10, valueState.value().intValue());

        
        valueState
                .asyncClear()
                .thenAccept(
                        clear -> {
                            valueState
                                    .asyncUpdate(20)
                                    .thenAccept(
                                            update -> {
                                                assertEquals(20, valueState.value().intValue());
                                            });
                        });
    }

Line commented on: assertEquals(10, valueState.value().intValue());

Revised code:
public void testAdapt() throws Exception {
        KeyedStateBackend<Integer> keyedStateBackend = new TestKeyedStateBackend();
        AsyncKeyedStateBackendAdaptor<Integer> adaptor =
                new AsyncKeyedStateBackendAdaptor<>(keyedStateBackend);
        StateDescriptor<Integer> descriptor =
                new ValueStateDescriptor<>("testState", BasicTypeInfo.INT_TYPE_INFO);

        org.apache.flink.api.common.state.v2.ValueState<Integer> valueState =
                adaptor.createState(
                        VoidNamespace.INSTANCE, VoidNamespaceSerializer.INSTANCE, descriptor);

        
        valueState.clear();
        assertThat(valueState.value()).isNull();
        valueState.update(10);
        assertThat(valueState.value()).isEqualTo(10);

        
        valueState
                .asyncClear()
                .thenAccept(
                        clear -> {
                            assertThat(valueState.value()).isNull();
                            valueState
                                    .asyncUpdate(20)
                                    .thenCompose(
                                            empty -> {
                                                assertThat(valueState.value()).isEqualTo(20);
                                                return valueState.asyncValue();
                                            })
                                    .thenAccept(
                                            value -> {
                                                assertThat(value).isEqualTo(20);
                                            });
                        });
    }
Code review comment: Shall we add java docs to this public method

Code under review:
protected static MapValue getPathParamOrderMap(AttachedFunction resource) {
        Object annotation = resource.getAnnotation(HTTP_PACKAGE_PATH, ANN_NAME_PARAM_ORDER_CONFIG);
        return annotation == null ? new MapValueImpl() :
                (MapValue) ((MapValue) annotation).get(ANN_FIELD_PATH_PARAM_ORDER);
    }

Line commented on: return annotation == null ? new MapValueImpl() :

Revised code:
protected static MapValue getPathParamOrderMap(AttachedFunction resource) {
        Object annotation = resource.getAnnotation(HTTP_PACKAGE_PATH, ANN_NAME_PARAM_ORDER_CONFIG);
        return annotation == null ? new MapValueImpl() :
                (MapValue) ((MapValue) annotation).get(ANN_FIELD_PATH_PARAM_ORDER);
    }
Code review comment: Could you please move such logic to the lines since no data in a partition is just a special case for it.  ```java if (partitionColumnSize > 0) { xxx } ```

Code under review:
public void commitPartitions() throws Exception {
        FileSystem fs = factory.create(tmpPath.toUri());
        List<Path> taskPaths = listTaskTemporaryPaths(fs, tmpPath);
        if (taskPaths.isEmpty() && !staticPartitions.isEmpty()) {
            commitEmptyPartition(fs);
            return;
        }
        try (PartitionLoader loader = new PartitionLoader(overwrite, fs, metaStoreFactory)) {
            if (partitionColumnSize > 0) {
                for (Map.Entry<LinkedHashMap<String, String>, List<Path>> entry :
                        collectPartSpecToPaths(fs, taskPaths, partitionColumnSize).entrySet()) {
                    loader.loadPartition(entry.getKey(), entry.getValue());
                }
            } else {
                loader.loadNonPartition(taskPaths);
            }
        } finally {
            for (Path taskPath : taskPaths) {
                fs.delete(taskPath, true);
            }
        }
    }

Line commented on: if (taskPaths.isEmpty() && !staticPartitions.isEmpty()) {

Revised code:
public void commitPartitions() throws Exception {
        FileSystem fs = factory.create(tmpPath.toUri());
        List<Path> taskPaths = listTaskTemporaryPaths(fs, tmpPath);

        try (PartitionLoader loader =
                new PartitionLoader(overwrite, fs, metaStoreFactory, isToLocal)) {
            if (partitionColumnSize > 0) {
                if (taskPaths.isEmpty() && !staticPartitions.isEmpty()) {
                    loader.loadEmptyPartition(this.staticPartitions);
                } else {
                    for (Map.Entry<LinkedHashMap<String, String>, List<Path>> entry :
                            collectPartSpecToPaths(fs, taskPaths, partitionColumnSize).entrySet()) {
                        loader.loadPartition(entry.getKey(), entry.getValue());
                    }
                }
            } else {
                loader.loadNonPartition(taskPaths);
            }
        } finally {
            for (Path taskPath : taskPaths) {
                fs.delete(taskPath, true);
            }
        }
    }
Code review comment: If columnSet.getString ("REMARKS") is null,  is this a safe behavior?

Code under review:
public List<Column> convertToSRTable(ResultSet columnSet) throws SQLException {
        List<Column> fullSchema = Lists.newArrayList();
        while (columnSet.next()) {
            Type type = convertColumnType(columnSet.getInt("DATA_TYPE"),
                    columnSet.getString("TYPE_NAME"),
                    columnSet.getInt("COLUMN_SIZE"),
                    columnSet.getInt("DECIMAL_DIGITS"));
            fullSchema.add(new Column(columnSet.getString("COLUMN_NAME"), type,
                    columnSet.getString("IS_NULLABLE").equals("YES"),
                    columnSet.getString("REMARKS")));
        }
        return fullSchema;
    }

Line commented on: columnSet.getString("REMARKS")));

Revised code:
public List<Column> convertToSRTable(ResultSet columnSet) throws SQLException {
        List<Column> fullSchema = Lists.newArrayList();
        while (columnSet.next()) {
            Type type = convertColumnType(columnSet.getInt("DATA_TYPE"),
                    columnSet.getString("TYPE_NAME"),
                    columnSet.getInt("COLUMN_SIZE"),
                    columnSet.getInt("DECIMAL_DIGITS"));

            String comment = "";
            
            try {
                if (columnSet.getString("REMARKS") != null) {
                    comment = columnSet.getString("REMARKS");
                }
            } catch (SQLException ignored) { }

            fullSchema.add(new Column(columnSet.getString("COLUMN_NAME"), type,
                    columnSet.getString("IS_NULLABLE").equals("YES"), comment));
        }
        return fullSchema;
    }
Code review comment: add a white space  `"interrupted...` => `" interrupted...`

Code under review:
private void loop() throws Exception {
		while (!wasClosed) {
			try {
				dispatcher.dispatch(deque.take());
			} catch (InterruptedException e) {
				if (!wasClosed) {
					LOG.debug(taskName + "interrupted while waiting for a request (continue waiting)", e);
				} else {
					Thread.currentThread().interrupt();
				}
			}
		}
	}

Line commented on: LOG.debug(taskName + "interrupted while waiting for a request (continue waiting)", e);

Revised code:
private void loop() throws Exception {
		while (!wasClosed) {
			try {
				dispatcher.dispatch(deque.take());
			} catch (InterruptedException e) {
				if (!wasClosed) {
					LOG.debug(taskName + " interrupted while waiting for a request (continue waiting)", e);
				} else {
					Thread.currentThread().interrupt();
				}
			}
		}
	}
Code review comment: Done. There was an issue with try-with-resources closing the output stream before writing to the file. Due to that I separately closed both the output stream and the file writer inside the finally block.

Code under review:
private static void writeFile(String filePath, String content) throws IOException {
        OutputStreamWriter fileWriter = null;
        try {
            File newFile = new File(filePath);
            FileOutputStream fileStream = new FileOutputStream(newFile);
            fileWriter = new OutputStreamWriter(fileStream, StandardCharsets.UTF_8);
            fileWriter.write(content);
        } finally {
            if (fileWriter != null) {
                fileWriter.close();
            }
        }
    }

Line commented on: FileOutputStream fileStream = new FileOutputStream(newFile);

Revised code:
private static void writeFile(String filePath, String content) throws IOException {
        OutputStreamWriter fileWriter = null;
        FileOutputStream fileStream = null;
        try {
            File newFile = new File(filePath);
            fileStream = new FileOutputStream(newFile);
            fileWriter = new OutputStreamWriter(fileStream, StandardCharsets.UTF_8);
            fileWriter.write(content);
        } finally {
            if (fileWriter != null) {
                fileWriter.close();
            }
            if (fileStream != null) {
                fileStream.close();
            }
        }
    }
Code review comment: It's better to overwrite old record, but not `ON DUPLICATE KEY UPDATE NOTHING`

Code under review:
public String buildInsertSQL(final Record record) {
        String insertSql = super.buildInsertSQL(record);
        if (!record.getTableMetaData().getUniqueKeyNamesList().isEmpty()) {
            return insertSql + " ON DUPLICATE KEY UPDATE NOTHING";
        }
        return insertSql;
    }

Line commented on: return insertSql + " ON DUPLICATE KEY UPDATE NOTHING";

Revised code:
public String buildInsertSQL(final Record record) {
        String insertSql = super.buildInsertSQL(record);
        List<String> uniqueKeyNamesList = record.getTableMetaData().getUniqueKeyNamesList();
        if (uniqueKeyNamesList.isEmpty()) {
            return insertSql;
        }
        StringBuilder updateValue = new StringBuilder();
        for (String each : record.getAfterMap().keySet()) {
            if (uniqueKeyNamesList.contains(each)) {
                continue;
            }
            updateValue.append(quote(each)).append("=EXCLUDED.").append(quote(each)).append(",");
        }
        updateValue.setLength(updateValue.length() - 1);
        String uniqueKeyNames = uniqueKeyNamesList.stream().map(this::quote).collect(Collectors.joining(","));
        return insertSql + String.format(" ON CONFLICT (%s) DO UPDATE SET %s", uniqueKeyNames, updateValue);
    }
Code review comment: We should use another method, error(String, Throwable) here.

Code under review:
public AbstractAuthenticationToken convert(Jwt jwt) {
        OAuth2AccessToken accessToken = new OAuth2AccessToken(
            OAuth2AccessToken.TokenType.BEARER, jwt.getTokenValue(), jwt.getIssuedAt(), jwt.getExpiresAt());
        AbstractAuthenticationToken token = this.jwtAuthenticationConverter.convert(jwt);
        Collection<GrantedAuthority> authorities = token.getAuthorities();
        JWTClaimsSet.Builder builder = new Builder();
        for (Entry<String, Object> entry : jwt.getClaims().entrySet()) {
            builder.claim(entry.getKey(), entry.getValue());
        }
        JWTClaimsSet jwtClaimsSet = builder.build();
        JWSObject jwsObject = null;
        try {
            jwsObject = JWSObject.parse(accessToken.getTokenValue());
        } catch (ParseException e) {
            LOGGER.error(
                e.getMessage() + ". When create an instance of JWSObject, an exception is resolved on the token.");
        }
        UserPrincipal userPrincipal = new UserPrincipal(accessToken.getTokenValue(), jwsObject, jwtClaimsSet);
        return new PreAuthenticatedAuthenticationToken(userPrincipal, null, authorities);
    }

Line commented on: LOGGER.error(

Revised code:
public AbstractAuthenticationToken convert(Jwt jwt) {
        OAuth2AccessToken accessToken = new OAuth2AccessToken(
            OAuth2AccessToken.TokenType.BEARER, jwt.getTokenValue(), jwt.getIssuedAt(), jwt.getExpiresAt());
        Collection<GrantedAuthority> authorities = extractAuthorities(jwt);
        AzureOAuth2AuthenticatedPrincipal principal = new AzureOAuth2AuthenticatedPrincipal(
            jwt.getHeaders(), jwt.getClaims(), authorities, jwt.getTokenValue());
        return new BearerTokenAuthentication(principal, accessToken, authorities);
    }
Code review comment: nit: It is still Thread.sleep(1), look into its implementation. TBH, I don't know what's the point of the method in jvm.

Code under review:
private void buildGraph(StreamExecutionEnvironment env) {
        
        
        env.fromSource(
                        new NumberSequenceSource(0, Long.MAX_VALUE),
                        WatermarkStrategy.noWatermarks(),
                        "num-source")
                
                .keyBy(value -> value)
                
                .map(
                        value -> {
                            Thread.sleep(0, 100);
                            return value;
                        })
                .addSink(new DiscardingSink<>());
    }

Line commented on: Thread.sleep(0, 100);

Revised code:
private void buildGraph(StreamExecutionEnvironment env) {
        
        
        env.fromSource(
                        new NumberSequenceSource(0, Long.MAX_VALUE),
                        WatermarkStrategy.noWatermarks(),
                        "num-source")
                
                .keyBy(value -> value)
                
                .map(
                        value -> {
                            Thread.sleep(1);
                            return value;
                        })
                .addSink(new DiscardingSink<>());
    }