paul-rogers commented on a change in pull request #2044: DRILL-7678: Update Yauaa Dependency URL: https://github.com/apache/drill/pull/2044#discussion_r402485830
########## File path: contrib/udfs/src/main/java/org/apache/drill/exec/udfs/UserAgentAnalyzerProvider.java ########## @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.drill.exec.udfs; + +import nl.basjes.parse.useragent.UserAgentAnalyzer; + +public class UserAgentAnalyzerProvider { + + public static UserAgentAnalyzer getInstance() { + return UserAgentAnalyzerHolder.INSTANCE; + } + + private static class UserAgentAnalyzerHolder { + private static final UserAgentAnalyzer INSTANCE = UserAgentAnalyzer.newBuilder() Review comment: @arina-ielchiieva, thanks; that article is accurate in the case that class `Something` is loaded earlier than the first use of `getInstance()`. Maybe there are other static functions or constants that force earlier class loading. In this specific case, the only method is `getInstance()` and so the outer class won't be loaded until that time. This means that the inner and outer classes are load at essentially the same time: on that first call to `getInstance()`. We can commit his PR with the code as it is; it works fine. My concern, however, is that we use static instances all over, and we've kind of relied on the behavior I've been describing. To be consistent, we'd want to go and change all the other uses as well. But, doing so would be unnecessary work in cases, like this one, where a single layer works fine. Let's go ahead and commit this, then we can continue the discussion without slowing this PR. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
