问:
evaluating logged in user from security principals in spring data rest
I'm writing a hateoas restful webservices where I have to supply the loggedin user to the front end through an API call once the user is authenticated via CAS.

For this, I added a search like this

```<code>package com.example.domain.repositories;

import com.example.domain.entities.User;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource(path = "users", collectionResourceRel = "users")
public interface UserRepository extends PagingAndSortingRepository<User, Integer> {

    @Query("SELECT user from User user where user.userName = ?#{principal.username}")
    User findCurrentUser();
}
</code>```

but when I'm accessing the url http://localhost:8080/api/users/search/findCurrentUser, It throws the following error.

```<code>Sat Jun 03 16:40:32 IST 2017
There was an unexpected error (type=Internal Server Error, status=500).
EL1008E: Property or field 'principal' cannot be found on object of type 'java.lang.Object[]' - maybe not public?
</code>```

Full Stacktrace::

```org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'principal' cannot be found on object of type 'java.lang.Object[]' - maybe not public?
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:224) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:81) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:51) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:87) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:299) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.data.jpa.repository.query.SpelExpressionStringQueryParameterBinder.evaluateExpression(SpelExpressionStringQueryParameterBinder.java:131) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.SpelExpressionStringQueryParameterBinder.potentiallyBindExpressionParameters(SpelExpressionStringQueryParameterBinder.java:89) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.SpelExpressionStringQueryParameterBinder.bind(SpelExpressionStringQueryParameterBinder.java:69) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:161) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:152) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.doCreateQuery(AbstractStringBasedJpaQuery.java:81) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:190) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:206) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:85) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:116) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:106) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:483) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at com.sun.proxy.$Proxy111.findByLoginStatus(Unknown Source) ~[na:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:216) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.data.repository.support.ReflectionRepositoryInvoker.invoke(ReflectionRepositoryInvoker.java:265) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.data.repository.support.ReflectionRepositoryInvoker.invokeQueryMethod(ReflectionRepositoryInvoker.java:206) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory$UnwrappingRepositoryInvoker.invokeQueryMethod(UnwrappingRepositoryInvokerFactory.java:150) ~[spring-data-rest-core-2.6.3.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.RepositorySearchController.executeQueryMethod(RepositorySearchController.java:362) ~[spring-data-rest-webmvc-2.6.3.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.RepositorySearchController.executeSearch(RepositorySearchController.java:183) ~[spring-data-rest-webmvc-2.6.3.RELEASE.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[servlet-api.jar:na]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[servlet-api.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-websocket.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:84) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:82) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:185) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:115) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter.access$000(ErrorPageFilter.java:59) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:90) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:108) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) [catalina.jar:8.0.38]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.38]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [catalina.jar:8.0.38]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [catalina.jar:8.0.38]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.38]
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) [catalina.jar:8.0.38]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.38]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) [catalina.jar:8.0.38]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100) [tomcat-coyote.jar:8.0.38]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687) [tomcat-coyote.jar:8.0.38]
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2508) [tomcat-coyote.jar:8.0.38]
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2497) [tomcat-coyote.jar:8.0.38]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.38]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
```

答:
Thanks to N4zroth for pointing out. Spring expression language did not resolve to security context variables as the dependency for spring-security-data was not added to the project.

Added the following dependency to my project and issue resolved.

```<code><dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-data</artifactId>
  <version>4.2.2.RELEASE</version>
</dependency>
</code>```

Body:
I'm writing a hateoas restful webservices where I have to supply the loggedin user to the front end through an API call once the user is authenticated via CAS.

For this, I added a search like this

package com.example.domain.repositories;

import com.example.domain.entities.User;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource(path = "users", collectionResourceRel = "users")
public interface UserRepository extends PagingAndSortingRepository<User, Integer> {

    @Query("SELECT user from User user where user.userName = ?#{principal.username}")
    User findCurrentUser();
}

but when I'm accessing the url http://localhost:8080/api/users/search/findCurrentUser, It throws the following error.

Sat Jun 03 16:40:32 IST 2017
There was an unexpected error (type=Internal Server Error, status=500).
EL1008E: Property or field 'principal' cannot be found on object of type 'java.lang.Object[]' - maybe not public?

Full Stacktrace::

org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'principal' cannot be found on object of type 'java.lang.Object[]' - maybe not public?
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:224) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:81) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:51) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:87) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:299) ~[spring-expression-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.data.jpa.repository.query.SpelExpressionStringQueryParameterBinder.evaluateExpression(SpelExpressionStringQueryParameterBinder.java:131) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.SpelExpressionStringQueryParameterBinder.potentiallyBindExpressionParameters(SpelExpressionStringQueryParameterBinder.java:89) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.SpelExpressionStringQueryParameterBinder.bind(SpelExpressionStringQueryParameterBinder.java:69) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:161) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:152) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.doCreateQuery(AbstractStringBasedJpaQuery.java:81) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:190) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:206) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:85) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:116) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:106) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:483) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:461) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.11.3.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at com.sun.proxy.$Proxy111.findByLoginStatus(Unknown Source) ~[na:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:216) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.data.repository.support.ReflectionRepositoryInvoker.invoke(ReflectionRepositoryInvoker.java:265) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.data.repository.support.ReflectionRepositoryInvoker.invokeQueryMethod(ReflectionRepositoryInvoker.java:206) ~[spring-data-commons-1.13.3.RELEASE.jar:na]
    at org.springframework.data.rest.core.support.UnwrappingRepositoryInvokerFactory$UnwrappingRepositoryInvoker.invokeQueryMethod(UnwrappingRepositoryInvokerFactory.java:150) ~[spring-data-rest-core-2.6.3.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.RepositorySearchController.executeQueryMethod(RepositorySearchController.java:362) ~[spring-data-rest-webmvc-2.6.3.RELEASE.jar:na]
    at org.springframework.data.rest.webmvc.RepositorySearchController.executeSearch(RepositorySearchController.java:183) ~[spring-data-rest-webmvc-2.6.3.RELEASE.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[servlet-api.jar:na]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[servlet-api.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-websocket.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:84) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:82) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:185) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:115) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter.access$000(ErrorPageFilter.java:59) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:90) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:108) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.38]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.38]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) [catalina.jar:8.0.38]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.38]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [catalina.jar:8.0.38]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [catalina.jar:8.0.38]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.38]
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) [catalina.jar:8.0.38]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.38]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) [catalina.jar:8.0.38]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100) [tomcat-coyote.jar:8.0.38]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687) [tomcat-coyote.jar:8.0.38]
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2508) [tomcat-coyote.jar:8.0.38]
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2497) [tomcat-coyote.jar:8.0.38]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.38]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]

Body:
Thanks to N4zroth for pointing out. Spring expression language did not resolve to security context variables as the dependency for spring-security-data was not added to the project.

Added the following dependency to my project and issue resolved.

<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-data</artifactId>
  <version>4.2.2.RELEASE</version>
</dependency>


来源: stackexchange

问:
Excel VBA link two user selected cells with hyperlink
I am currently trying to link two user selected cells automatically with hyperlinks.
The user can select two different cells (one after another via inputboxes). To those two cells hyperlinks should be added which point from cell 1 to cell 2 and cell 2 to cell 1.

So far I have this:

```<code> Option Explicit

Sub Hyperlinks()
Dim FirstHyperlink As Range
Dim SecondHyperlink As Range

Set FirstHyperlink = Application.InputBox("Please select first cell to contain hyperlink", "Hyperlink 1 selection", Type:=8)
Set SecondHyperlink = Application.InputBox("Please select second cell to contain hyperlink", "Hyperlink 2 selection", Type:=8)

ActiveSheet.Hyperlinks.Add Anchor:=FirstHyperlink.Address, Address:="", SubAddress:= _
    SecondHyperlink.Address, TextToDisplay:=FirstHyperlink.Value

ActiveSheet.Hyperlinks.Add Anchor:=SecondHyperlink.Address, Address:="", SubAddress:= _
    FirstHyperlink.Address, TextToDisplay:=SecondHyperlink.Value

End Sub
</code>```

However I get a run-time error 13: Type mismatch pointing to

```<code>ActiveSheet.Hyperlinks.Add Anchor:=FirstHyperlink.Address, Address:="", SubAddress:= _
        SecondHyperlink.Address, TextToDisplay:=FirstHyperlink.Value
</code>```

Anyone an idea what causes the problem?

答:
Just fix your Anchors:

```<code>Option Explicit

Sub Hyperlinks()
Dim FirstHyperlink As Range
Dim SecondHyperlink As Range

Set FirstHyperlink = Application.InputBox("Please select first cell to contain hyperlink", "Hyperlink 1 selection", Type:=8)
Set SecondHyperlink = Application.InputBox("Please select second cell to contain hyperlink", "Hyperlink 2 selection", Type:=8)

ActiveSheet.Hyperlinks.Add Anchor:=FirstHyperlink, Address:="", SubAddress:= _
    SecondHyperlink.Address, TextToDisplay:=FirstHyperlink.Value

ActiveSheet.Hyperlinks.Add Anchor:=SecondHyperlink, Address:="", SubAddress:= _
    FirstHyperlink.Address, TextToDisplay:=SecondHyperlink.Value

End Sub
</code>```

This assumes that the cells have some non-null values to begin with.

ContentLicense: CC BY-SA 3.0

Body:
I am currently trying to link two user selected cells automatically with hyperlinks.
The user can select two different cells (one after another via inputboxes). To those two cells hyperlinks should be added which point from cell 1 to cell 2 and cell 2 to cell 1.

So far I have this:

 Option Explicit

Sub Hyperlinks()
Dim FirstHyperlink As Range
Dim SecondHyperlink As Range

Set FirstHyperlink = Application.InputBox("Please select first cell to contain hyperlink", "Hyperlink 1 selection", Type:=8)
Set SecondHyperlink = Application.InputBox("Please select second cell to contain hyperlink", "Hyperlink 2 selection", Type:=8)

ActiveSheet.Hyperlinks.Add Anchor:=FirstHyperlink.Address, Address:="", SubAddress:= _
    SecondHyperlink.Address, TextToDisplay:=FirstHyperlink.Value

ActiveSheet.Hyperlinks.Add Anchor:=SecondHyperlink.Address, Address:="", SubAddress:= _
    FirstHyperlink.Address, TextToDisplay:=SecondHyperlink.Value

End Sub

However I get a run-time error 13: Type mismatch pointing to

ActiveSheet.Hyperlinks.Add Anchor:=FirstHyperlink.Address, Address:="", SubAddress:= _
        SecondHyperlink.Address, TextToDisplay:=FirstHyperlink.Value

Anyone an idea what causes the problem?

Body:
Just fix your Anchors:

Option Explicit

Sub Hyperlinks()
Dim FirstHyperlink As Range
Dim SecondHyperlink As Range

Set FirstHyperlink = Application.InputBox("Please select first cell to contain hyperlink", "Hyperlink 1 selection", Type:=8)
Set SecondHyperlink = Application.InputBox("Please select second cell to contain hyperlink", "Hyperlink 2 selection", Type:=8)

ActiveSheet.Hyperlinks.Add Anchor:=FirstHyperlink, Address:="", SubAddress:= _
    SecondHyperlink.Address, TextToDisplay:=FirstHyperlink.Value

ActiveSheet.Hyperlinks.Add Anchor:=SecondHyperlink, Address:="", SubAddress:= _
    FirstHyperlink.Address, TextToDisplay:=SecondHyperlink.Value

End Sub

This assumes that the cells have some non-null values to begin with.


问:
Cannot Build Ionic App - AngularFire2 Build Error
I started using firebase in my Ionic App. Everything works and I can use the app in the browser. However, whenever I try to build the app for android using the command ionic cordova build android, it shows a build error as follows:

```<code>Error: ./~/firebase/app/shared_promise.js
Module not found: Error: Can't resolve 'promise-polyfill' in 'D:\mychat\node_modules\firebase\app'
resolve 'promise-polyfill' in 'D:\mychat\node_modules\firebase\app'
  Parsed request is a module
  using description file: D:\mychat\node_modules\firebase\package.json (relative path: ./app)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: D:\mychat\node_modules\firebase\package.json (relative path: ./app)
    resolve as module
      looking for modules in D:\mychat\node_modules
        using description file: D:\mychat\package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: D:\mychat\package.json (relative path: ./node_modules)
          using description file: D:\mychat\package.json (relative path: ./node_modules/promise-polyfill)
            as directory
              D:\mychat\node_modules\promise-polyfill doesn't exist
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              D:\mychat\node_modules\promise-polyfill doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              D:\mychat\node_modules\promise-polyfill.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              D:\mychat\node_modules\promise-polyfill.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              D:\mychat\node_modules\promise-polyfill.json doesn't exist
[D:\mychat\node_modules\promise-polyfill]
[D:\mychat\node_modules\promise-polyfill]
[D:\mychat\node_modules\promise-polyfill.ts]
[D:\mychat\node_modules\promise-polyfill.js]
[D:\mychat\node_modules\promise-polyfill.json]
 @ ./~/firebase/app/shared_promise.js 37:35-62
 @ ./~/firebase/app/firebase_app.js
 @ ./~/firebase/app.js
 @ ./~/firebase/auth.js
 @ ./~/angularfire2/auth/auth.js
 @ ./~/angularfire2/auth.js
 @ ./src/app/app.module.ts
 @ ./src/app/main.ts
</code>```

This is my package.json:

```<code>{
  "name": "mychat",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "4.1.2",
    "@angular/compiler": "4.1.2",
    "@angular/compiler-cli": "4.1.2",
    "@angular/core": "4.1.2",
    "@angular/forms": "4.1.2",
    "@angular/http": "4.1.2",
    "@angular/platform-browser": "4.1.2",
    "@angular/platform-browser-dynamic": "4.1.2",
    "@ionic-native/core": "3.7.0",
    "@ionic-native/splash-screen": "3.7.0",
    "@ionic-native/status-bar": "3.7.0",
    "@ionic/storage": "2.0.1",
    "angularfire2": "^4.0.0-rc.0",
    "cordova-android": "^6.2.3",
    "cordova-plugin-console": "^1.0.5",
    "cordova-plugin-device": "^1.1.4",
    "cordova-plugin-splashscreen": "^4.0.3",
    "cordova-plugin-statusbar": "^2.2.2",
    "cordova-plugin-whitelist": "^1.3.1",
    "firebase": "^4.0.0",
    "ionic-angular": "3.3.0",
    "ionic-plugin-keyboard": "^2.2.1",
    "ionicons": "3.0.0",
    "rxjs": "5.1.1",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.10"
  },
  "devDependencies": {
    "@angular/cli": "^1.0.6",
    "@ionic/app-scripts": "1.3.7",
    "@ionic/cli-plugin-cordova": "1.2.1",
    "@ionic/cli-plugin-ionic-angular": "1.2.0",
    "typescript": "2.3.3"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-console": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-whitelist": {},
      "ionic-plugin-keyboard": {}
    },
    "platforms": [
      "android"
    ]
  }
}
</code>```

Any suggestions?

答: just as @nickmcblain suggested in the comments, all I had to do was install promise-polyfill and the build worked.

Body:
I started using firebase in my Ionic App. Everything works and I can use the app in the browser. However, whenever I try to build the app for android using the command ionic cordova build android, it shows a build error as follows:

Error: ./~/firebase/app/shared_promise.js
Module not found: Error: Can't resolve 'promise-polyfill' in 'D:\mychat\node_modules\firebase\app'
resolve 'promise-polyfill' in 'D:\mychat\node_modules\firebase\app'
  Parsed request is a module
  using description file: D:\mychat\node_modules\firebase\package.json (relative path: ./app)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: D:\mychat\node_modules\firebase\package.json (relative path: ./app)
    resolve as module
      looking for modules in D:\mychat\node_modules
        using description file: D:\mychat\package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: D:\mychat\package.json (relative path: ./node_modules)
          using description file: D:\mychat\package.json (relative path: ./node_modules/promise-polyfill)
            as directory
              D:\mychat\node_modules\promise-polyfill doesn't exist
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              D:\mychat\node_modules\promise-polyfill doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              D:\mychat\node_modules\promise-polyfill.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              D:\mychat\node_modules\promise-polyfill.js doesn't exist
            .json
              Field 'browser' doesn't contain a valid alias configuration
              D:\mychat\node_modules\promise-polyfill.json doesn't exist
[D:\mychat\node_modules\promise-polyfill]
[D:\mychat\node_modules\promise-polyfill]
[D:\mychat\node_modules\promise-polyfill.ts]
[D:\mychat\node_modules\promise-polyfill.js]
[D:\mychat\node_modules\promise-polyfill.json]
 @ ./~/firebase/app/shared_promise.js 37:35-62
 @ ./~/firebase/app/firebase_app.js
 @ ./~/firebase/app.js
 @ ./~/firebase/auth.js
 @ ./~/angularfire2/auth/auth.js
 @ ./~/angularfire2/auth.js
 @ ./src/app/app.module.ts
 @ ./src/app/main.ts

This is my package.json:

{
  "name": "mychat",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "4.1.2",
    "@angular/compiler": "4.1.2",
    "@angular/compiler-cli": "4.1.2",
    "@angular/core": "4.1.2",
    "@angular/forms": "4.1.2",
    "@angular/http": "4.1.2",
    "@angular/platform-browser": "4.1.2",
    "@angular/platform-browser-dynamic": "4.1.2",
    "@ionic-native/core": "3.7.0",
    "@ionic-native/splash-screen": "3.7.0",
    "@ionic-native/status-bar": "3.7.0",
    "@ionic/storage": "2.0.1",
    "angularfire2": "^4.0.0-rc.0",
    "cordova-android": "^6.2.3",
    "cordova-plugin-console": "^1.0.5",
    "cordova-plugin-device": "^1.1.4",
    "cordova-plugin-splashscreen": "^4.0.3",
    "cordova-plugin-statusbar": "^2.2.2",
    "cordova-plugin-whitelist": "^1.3.1",
    "firebase": "^4.0.0",
    "ionic-angular": "3.3.0",
    "ionic-plugin-keyboard": "^2.2.1",
    "ionicons": "3.0.0",
    "rxjs": "5.1.1",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.10"
  },
  "devDependencies": {
    "@angular/cli": "^1.0.6",
    "@ionic/app-scripts": "1.3.7",
    "@ionic/cli-plugin-cordova": "1.2.1",
    "@ionic/cli-plugin-ionic-angular": "1.2.0",
    "typescript": "2.3.3"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-console": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-whitelist": {},
      "ionic-plugin-keyboard": {}
    },
    "platforms": [
      "android"
    ]
  }
}

Any suggestions?


问:
C++11: Avoid downcasting when setting member variables for derived class
Let's say I want to build a Car which has components like Motor, Tire, etc. which are all derived from a "component" base class. Each component has its own states (i.e. motor has RPM, tire has pressure, and so on) as a subclass. A Car class stores all component classes.

Now I want the Car class to have a "save car states" function which returns an object that loops over a vector of all components and holds all states of all components to restore them later. Each component should individually be responsible of storing and restoring its states to the car state object.

The code below is a minimal example of what I came up with. However it has (at least) two ugly parts in the code, which I think should be avoided:

First, I need to downcast a Base class of states, when I want to set the car components back to a previously saved state. Is this a valid case to downcast? I read that this is usually a sign of bad design. Thus, how can I improve this? Did I completely misuse the concept of polymorphism?

Second, I need to get the raw pointer of an unique_ptr to pass the state back to the component and read it there. Seems pretty ugly to me as well.
Thanks for your comments!

This is my code:

```<code>#include <iostream>
#include <vector>

class StateClass{
};

class component{
public:
  virtual std::unique_ptr<StateClass> saveStates() = 0;
  virtual void loadStates(StateClass* states) = 0;
};

class Motor:public component
{
public:
  Motor(){
    mstates.rpm = 6000;
    mstates.motorstates::oilLevel = 1.0;
  }
  struct motorstates: public StateClass{
    double rpm;
    double oilLevel;
    void setStates(){
    }
  };

  std::unique_ptr<StateClass> saveStates(){
    std::unique_ptr<StateClass> tmp(new motorstates(mstates));
    return tmp;
  };

  void loadStates(StateClass* states){
    motorstates* savedState = static_cast<motorstates*>(states); // <=== should this be avoided??
    mstates.rpm = savedState->rpm;
    mstates.oilLevel = savedState->oilLevel;
  };

// private:
  void someMethod1();
  void someMethod2();
  motorstates mstates;
};

class Car{
public:
  Car(){
    listOfComponents.push_back(&amotor);
  }
  std::vector<component*> listOfComponents;

// private:
  Motor amotor;

  std::vector<std::unique_ptr<StateClass>> saveState(){
    std::vector<std::unique_ptr<StateClass> > states;
    for(auto comp : listOfComponents){
      states.push_back(comp->saveStates());
    }
    return states;
  }

  void loadState(std::vector<std::unique_ptr<StateClass>>& savedStates){
    int cntstates = 0;
    for(auto comp: listOfComponents){
      comp->loadStates(savedStates.at(cntstates++).get());  // <=== this seems pretty ugly
    };
  }
};

int main()
{
  Car acar;

  std::cout << "Car rpm: " << acar.amotor.mstates.rpm << std::endl;

  std::cout << "Saving states..." << std::endl;
  std::vector<std::unique_ptr<StateClass>> savedState = acar.saveState();

  std::cout << "Changing car rpm..." << std::endl;
  acar.amotor.mstates.rpm = 5000;
  std::cout << "Current car rpm: " << acar.amotor.mstates.rpm << std::endl;

  StateClass* tmpState = savedState.at(0).get();
  Motor::motorstates* tmpMotorstates = static_cast<Motor::motorstates*>(tmpState);
  std::cout << "Saved rpm: " << tmpMotorstates->rpm << std::endl;

  std::cout << "Loading state... " << std::endl;
  acar.loadState(savedState);
  std::cout << "Current car rpm: " << acar.amotor.mstates.rpm << std::endl;

}
</code>```

Additional remarks (see comments):

I read about visitor classes, but they seem to complicate things more than they would help to write readable code.

I actually only need to save states during runtime, not to a file

The car was just an example. My real project uses lots of component classes with hundreds of states. Also some states are supposed to be restored, others not.

答:
Design issue

These ugly things are symptoms of a design issue caused by the mutual dependency between the Component structure and the State structure.

In other words, you have defined a polymorphic State, but most of the time you use it expecting a specific state subclass.

In addition, the configuration of the car is in fact also a state:  if you would change anything in its configuration, you'd no longer be able to restore anything (even if you just added an irrelevant spare-part).

Make your code more robust

If you keep this design, you should in any case make the code more robust.  What happens, for example, if by accident you give a State pointer which does not meet the expectations ?

```<code>motorstates* savedState = static_cast<motorstates*>(states);
</code>```

This would be UB ! Fortunately your state is already a polymorphic type.  So you could use dynamic cast instead:

```<code>motorstates* savedState = dynamic_cast<motorstates*>(states);
if (savedState==nullptr) {  // this is true if the state was not of correct class
    //ouch !  At least you'd know
}
</code>```

(By the way, as a rule of thumb that can prevent problems: if you've got a virtual member function, better give your class a virtual destructor.)

Alternative design 1:  the memento

A good option for a save/restore capability is to use a memento design pattern.  The idea is that the the obect saves or restores its state from a memento, which content and structure is unknown from the "caretaker" (i.e. the code responsible of keeping the memnto and invoke the safekeeping).

Consequence:  the internals of a CarMemento would be known to the Car only.  This leans that you'll not be able to restore a partial state (e.g. engine state only).  The mementos would not necessarily be polymorphic objects : the save state/restore state would anyway use specific Memento types for the different Components.

It seems that you have the components as private members and not as a dynamic item.  If this is confirmed this would be the safest way to do.

Alternative design 2: composite

Another approach would be adopt the composite design pattern for your component and combine it with the memento.

I'd then implement the state-saving using the principle of serialisation (even if it's into a memory object), and saveguard not only the states but the full composite structure. I'd then use a factory to deserialize a saved state.

However, if you prefer to save only the states of the object, you could combine composite with memento:

either giving the memnto's internals a composite structure, assuming that it replicates always the component that was saved.

or use some unique identifies to identify the components in the car, and construct the memento as a map container, which returns a state for  an identifier. This approach would have advantage that it's flexible in case you add or remove coponents from your care between the saving and teh restoring of the state.

In both case however, you'd have to use dynamic cast to ensure that the types of the saved state match with the type of the state to be restored.

Body:
Let's say I want to build a Car which has components like Motor, Tire, etc. which are all derived from a "component" base class. Each component has its own states (i.e. motor has RPM, tire has pressure, and so on) as a subclass. A Car class stores all component classes.

Now I want the Car class to have a "save car states" function which returns an object that loops over a vector of all components and holds all states of all components to restore them later. Each component should individually be responsible of storing and restoring its states to the car state object.

The code below is a minimal example of what I came up with. However it has (at least) two ugly parts in the code, which I think should be avoided:

First, I need to downcast a Base class of states, when I want to set the car components back to a previously saved state. Is this a valid case to downcast? I read that this is usually a sign of bad design. Thus, how can I improve this? Did I completely misuse the concept of polymorphism?

Second, I need to get the raw pointer of an unique_ptr to pass the state back to the component and read it there. Seems pretty ugly to me as well.
Thanks for your comments!

This is my code:

#include <iostream>
#include <vector>

class StateClass{
};

class component{
public:
  virtual std::unique_ptr<StateClass> saveStates() = 0;
  virtual void loadStates(StateClass* states) = 0;
};

class Motor:public component
{
public:
  Motor(){
    mstates.rpm = 6000;
    mstates.motorstates::oilLevel = 1.0;
  }
  struct motorstates: public StateClass{
    double rpm;
    double oilLevel;
    void setStates(){
    }
  };

  std::unique_ptr<StateClass> saveStates(){
    std::unique_ptr<StateClass> tmp(new motorstates(mstates));
    return tmp;
  };

  void loadStates(StateClass* states){
    motorstates* savedState = static_cast<motorstates*>(states); // <=== should this be avoided??
    mstates.rpm = savedState->rpm;
    mstates.oilLevel = savedState->oilLevel;
  };

// private:
  void someMethod1();
  void someMethod2();
  motorstates mstates;
};

class Car{
public:
  Car(){
    listOfComponents.push_back(&amotor);
  }
  std::vector<component*> listOfComponents;

// private:
  Motor amotor;

  std::vector<std::unique_ptr<StateClass>> saveState(){
    std::vector<std::unique_ptr<StateClass> > states;
    for(auto comp : listOfComponents){
      states.push_back(comp->saveStates());
    }
    return states;
  }

  void loadState(std::vector<std::unique_ptr<StateClass>>& savedStates){
    int cntstates = 0;
    for(auto comp: listOfComponents){
      comp->loadStates(savedStates.at(cntstates++).get());  // <=== this seems pretty ugly
    };
  }
};

int main()
{
  Car acar;

  std::cout << "Car rpm: " << acar.amotor.mstates.rpm << std::endl;

  std::cout << "Saving states..." << std::endl;
  std::vector<std::unique_ptr<StateClass>> savedState = acar.saveState();

  std::cout << "Changing car rpm..." << std::endl;
  acar.amotor.mstates.rpm = 5000;
  std::cout << "Current car rpm: " << acar.amotor.mstates.rpm << std::endl;

  StateClass* tmpState = savedState.at(0).get();
  Motor::motorstates* tmpMotorstates = static_cast<Motor::motorstates*>(tmpState);
  std::cout << "Saved rpm: " << tmpMotorstates->rpm << std::endl;

  std::cout << "Loading state... " << std::endl;
  acar.loadState(savedState);
  std::cout << "Current car rpm: " << acar.amotor.mstates.rpm << std::endl;

}

Additional remarks (see comments):

I read about visitor classes, but they seem to complicate things more than they would help to write readable code.

I actually only need to save states during runtime, not to a file

The car was just an example. My real project uses lots of component classes with hundreds of states. Also some states are supposed to be restored, others not.

Body:
Design issue

These ugly things are symptoms of a design issue caused by the mutual dependency between the Component structure and the State structure.

In other words, you have defined a polymorphic State, but most of the time you use it expecting a specific state subclass.

In addition, the configuration of the car is in fact also a state:  if you would change anything in its configuration, you'd no longer be able to restore anything (even if you just added an irrelevant spare-part).

Make your code more robust

If you keep this design, you should in any case make the code more robust.  What happens, for example, if by accident you give a State pointer which does not meet the expectations ?

motorstates* savedState = static_cast<motorstates*>(states);

This would be UB ! Fortunately your state is already a polymorphic type.  So you could use dynamic cast instead:

motorstates* savedState = dynamic_cast<motorstates*>(states);
if (savedState==nullptr) {  // this is true if the state was not of correct class
    //ouch !  At least you'd know
}

(By the way, as a rule of thumb that can prevent problems: if you've got a virtual member function, better give your class a virtual destructor.)

Alternative design 1:  the memento

A good option for a save/restore capability is to use a memento design pattern.  The idea is that the the obect saves or restores its state from a memento, which content and structure is unknown from the "caretaker" (i.e. the code responsible of keeping the memnto and invoke the safekeeping).

Consequence:  the internals of a CarMemento would be known to the Car only.  This leans that you'll not be able to restore a partial state (e.g. engine state only).  The mementos would not necessarily be polymorphic objects : the save state/restore state would anyway use specific Memento types for the different Components.

It seems that you have the components as private members and not as a dynamic item.  If this is confirmed this would be the safest way to do.

Alternative design 2: composite

Another approach would be adopt the composite design pattern for your component and combine it with the memento.

I'd then implement the state-saving using the principle of serialisation (even if it's into a memory object), and saveguard not only the states but the full composite structure. I'd then use a factory to deserialize a saved state.

However, if you prefer to save only the states of the object, you could combine composite with memento:

either giving the memnto's internals a composite structure, assuming that it replicates always the component that was saved.

or use some unique identifies to identify the components in the car, and construct the memento as a map container, which returns a state for  an identifier. This approach would have advantage that it's flexible in case you add or remove coponents from your care between the saving and teh restoring of the state.

In both case however, you'd have to use dynamic cast to ensure that the types of the saved state match with the type of the state to be restored.


问:
What optimizations does the Rust compiler make with `loop` versus `while true`?
Aside from the fact that it can reason about uninitialized values set within the loop body, are there any other compelling reasons for loop to exist ?

答:
Other than you state your intention, there is no difference. All loops are the same once normalization has happened in the compiler.

See an example of a loop in the Rust playground and the same example with a while true. The assembly generated is exactly the same. The compiler gives a warning for the while true-example to use loop instead.

Body:
Other than you state your intention, there is no difference. All loops are the same once normalization has happened in the compiler.

See an <a href="https://play.rust-lang.org/?code=%0Afn%20main()%20%7B%0A%20%20%20%20let%20mut%20x%20%3D%201000%3B%0A%20%20%20%20loop%20%7B%0A%20%20%20%20%20%20%20%20x%20-%3D%201%3B%0A%20%20%20%20%20%20%20%20if%20x%20%3D%3D%200%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20panic!(%22We%20ran%20out%20of%20money!%22)%3B%0A%20%20%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20println!(%22We%20still%20have%20money%20left%22)%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D&version=stable&backtrace=0" rel="nofollow noreferrer">example of a loop in the Rust playground and <a href="https://play.rust-lang.org/?code=%0Afn%20main()%20%7B%0A%20%20%20%20let%20mut%20x%20%3D%201000%3B%0A%20%20%20%20while%20true%20%7B%0A%20%20%20%20%20%20%20%20x%20-%3D%201%3B%0A%20%20%20%20%20%20%20%20if%20x%20%3D%3D%200%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20panic!(%22We%20ran%20out%20of%20money!%22)%3B%0A%20%20%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20println!(%22We%20still%20have%20money%20left%22)%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D&version=stable&backtrace=0" rel="nofollow noreferrer">the same example with a while true. The assembly generated is exactly the same. The compiler gives a warning for the while true-example to use loop instead.


问:
Stack Overflow-like URL routes in rails 3
So I want my app to generate routes like stack overflow

```<code>questions/:id/:title
</code>```

How can I do this in rails?

答:
This is what I was looking for:

http://norman.github.com/friendly_id/file.Guide.html

hope this can help others!

ContentLicense: CC BY-SA 2.5

Body:
So I want my app to generate routes like stack overflow

questions/:id/:title

How can I do this in rails?


问:
UICollectionView doesn't render cells
In my view I have a UITableView which contains cells with horizontal UICollectionView inside. The problem is that sometimes UICollectionViewCells are not rendered on device/simulator. At the same time I can see those cells in the View Hierarchy Debugger:

What I see in the View Hierarchy Debugger:

What I see on a device:

As you can see, cells (with images) exist and have correct frames and content (proved by the View Hierarchy Debugger). Nevertheless they are not rendered on device/simulator for some reason. What could be the cause of that and how could I fix it?

UPD: another example with "3D" view and bug on one cell, but not on the other

device screenshot:

view hierarchy debugger:

答:
It turned out that my particular problem is related to UICollectionView assertion error on stale data because sometimes mentioned crash happens. Playing around [collectionViewLayout invalidateLayout] I finally fixed this.

Just to record what was NOT the cause (and what you should check if faced with the same problem):

check if you update views in the main thread only

check if all autolayout constants are set correctly and don't conflict

check that your custom views' intrinsic content sizes are calculated correctly

If none of the above is the cause of issue try invalidateLayout somewhere around reloadData or inside of layoutSubviews or similar method.

Title: UICollectionView doesn't render cells


问:
Catchable fatal error: Object of class mysqli_result could not be converted to string on line 73
I am making a form for updating the data in the database, but it is throwing me this error Catchable fatal error: Object of class mysqli_result could not be converted to string on line 73

I have tried outputting all the data and all are printing but not updating in the database.

Please give some suggestion, how to solve it?

$id = $_GET['id'];
$t_id = $_GET['table_id'] - 2;

if(isset($_POST['submit'])){

  $name = $_POST['name'];
  $phone = $_POST['phone'];
  $email = $_POST['email'];
  $gender = intval($_POST['gender']);
  $treatment = intval($_POST['treatment']);
  $source = intval($_POST['source']);
  $status_ = intval($_POST['status']);
  $remark = $_POST['remark'];

//below code is line 73

$leadUpdateSql = "UPDATE lead SET
                     name = $name
                    ,phone = $phone
                    ,email = $email
                    ,gender_id = $gender
                    ,treatment_id = $treatment
                    ,source_id = $source
                    ,status_id = $status
                    ,remark = $remark
                     WHERE lead.id = $id";

if ($conn->query($leadUpdateSql) === TRUE) {
    echo "Record updated successfully";
    header("location:edit.php?id=$id&table_id=$t_id&updated=successfully");
   }

}```

答: make SQL with: email = '.$email.'. You've better print the SQL string and execute in MySQL CMD or PHPMyAdmin to find out.


问:
How can I write out correctly the download status in C# console app?
I have the following code, and it is working correctly except writing out the status of the download.

```<code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {

        static void clear()
        {

            Thread.Sleep(1500);
            Console.SetCursorPosition(0, 0);

        }

        static void Main(string[] args)
        {
            var client = new WebClient();

            client.DownloadProgressChanged += (o, e) =>
            {

                Console.Write(e.ProgressPercentage + "% ");
                clear();

            };

            client.DownloadFileAsync(new Uri("http://XXX"), "file");

            Console.ReadKey();

        }
    }
}
</code>```

With the code many new lines will be inserted and the status of the download will not be updated and printed out.

答:
DownloadProgressChanged event can be called by multiple threads concurrently, so you need to take care of it, for example using lock as shown bellow.

Also don't use Thread.Sleep() in event handler! It is never good idea. In this particular case, while thread is sleeping, download cannot continue, resulting in significantly slower download. If you want to limit frequency of updates to screen (to lower CPU load and avoid screen flickering), simply skip events that accurs too soon after previous event.

```<code>static void Main(string[] args)
{
    var client = new WebClient();

    Object LockObject = new Object();
    DateTime LastProgressUpdateTime = DateTime.MinValue;
    long LastProgressUpdatePosition = -1;
    TimeSpan DesiredProgressUpdatePeriod = TimeSpan.FromMilliseconds(1500);

    client.DownloadProgressChanged += (o, e) =>
    {
        //Prevent multipe concurrent thread to update progress at once
        lock (LockObject)
        {
            // This prevents updating progress to value that is lower than
            // what we already printed. This could happen when threads
            // enters lock out of order.
            if (LastProgressUpdatePosition > e.BytesReceived)
                return;

            // This is not neccessary, but prevents you to miss 100% progress event ()
            var isCompleted = e.TotalBytesToReceive != 0 && e.BytesReceived == e.TotalBytesToReceive;

            // Check if desired time elapsed since last update
            bool UpdatePeriodElapsed = DateTime.Now >= LastProgressUpdateTime + DesiredProgressUpdatePeriod;

            if(isCompleted || UpdatePeriodElapsed)
            {
                Console.SetCursorPosition(0, 0);
                Console.Write(e.ProgressPercentage + "%");
                LastProgressUpdatePosition = e.BytesReceived;
                LastProgressUpdateTime = DateTime.Now;
            }
        }
    };

    client.DownloadFileAsync(new Uri("..."), "...");
    Console.ReadKey();
}
</code>```

Body:
I have the following code, and it is working correctly except writing out the status of the download.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {

        static void clear()
        {

            Thread.Sleep(1500);
            Console.SetCursorPosition(0, 0);

        }

        static void Main(string[] args)
        {
            var client = new WebClient();

            client.DownloadProgressChanged += (o, e) =>
            {

                Console.Write(e.ProgressPercentage + "% ");
                clear();

            };

            client.DownloadFileAsync(new Uri("http://XXX"), "file");

            Console.ReadKey();

        }
    }
}

With the code many new lines will be inserted and the status of the download will not be updated and printed out.

Body:
DownloadProgressChanged event can be called by multiple threads concurrently, so you need to take care of it, for example using lock as shown bellow.

Also don't use Thread.Sleep() in event handler! It is never good idea. In this particular case, while thread is sleeping, download cannot continue, resulting in significantly slower download. If you want to limit frequency of updates to screen (to lower CPU load and avoid screen flickering), simply skip events that accurs too soon after previous event.

static void Main(string[] args)
{
    var client = new WebClient();

    Object LockObject = new Object();
    DateTime LastProgressUpdateTime = DateTime.MinValue;
    long LastProgressUpdatePosition = -1;
    TimeSpan DesiredProgressUpdatePeriod = TimeSpan.FromMilliseconds(1500);

    client.DownloadProgressChanged += (o, e) =>
    {
        //Prevent multipe concurrent thread to update progress at once
        lock (LockObject)
        {
            // This prevents updating progress to value that is lower than
            // what we already printed. This could happen when threads
            // enters lock out of order.
            if (LastProgressUpdatePosition > e.BytesReceived)
                return;

            // This is not neccessary, but prevents you to miss 100% progress event ()
            var isCompleted = e.TotalBytesToReceive != 0 && e.BytesReceived == e.TotalBytesToReceive;

            // Check if desired time elapsed since last update
            bool UpdatePeriodElapsed = DateTime.Now >= LastProgressUpdateTime + DesiredProgressUpdatePeriod;

            if(isCompleted || UpdatePeriodElapsed)
            {
                Console.SetCursorPosition(0, 0);
                Console.Write(e.ProgressPercentage + "%");
                LastProgressUpdatePosition = e.BytesReceived;
                LastProgressUpdateTime = DateTime.Now;
            }
        }
    };

    client.DownloadFileAsync(new Uri("..."), "...");
    Console.ReadKey();
}


问:
Dart - Play a loop of Futures
I have this function which plays a sound inside of Flutter using the audioplayer plugin.

```<code>play(int soundFrequency) async {
  final result = await audioPlayer.play("urltosound.wav");
}
</code>```

It works fine. But now I want to be able to play multiple sounds in a row. It seems as if I mess up with the futures. I tried this approach, which is very dirty and ugly but I was just trying to figure things out:

```<code>playRandomSequence() async {
  final result = audioPlayer.play("urltosound.wav").then(play2(pickRandomSoundFrequency()));
}
play2(int soundFrequency) async {
  final result = audioPlayer.play("urltosound.wav");
}
</code>```

Basically, as soon as the first future is over, I call the next one with the .then() method.

What I get from it is this error:

```<code>type '_Future' is not a subtype of type '(dynamic) => dynamic' of 'f' where _Future is from dart:async
</code>```

How can I fix this?

Thanks

答:
You have the wrong type for the argument of .then().  Try:

```<code>.then((_) => play2(pickRandomSoundFrequency()))
</code>```

You need to pass a function to be called, not call the function when constructing the arguments to then.

Title: Dart - Play a loop of Futures

Body:
I have this function which plays a sound inside of Flutter using the audioplayer plugin.

play(int soundFrequency) async {
  final result = await audioPlayer.play("urltosound.wav");
}

It works fine. But now I want to be able to play multiple sounds in a row. It seems as if I mess up with the futures. I tried this approach, which is very dirty and ugly but I was just trying to figure things out:

playRandomSequence() async {
  final result = audioPlayer.play("urltosound.wav").then(play2(pickRandomSoundFrequency()));
}
play2(int soundFrequency) async {
  final result = audioPlayer.play("urltosound.wav");
}

Basically, as soon as the first future is over, I call the next one with the .then() method.

What I get from it is this error:

type '_Future' is not a subtype of type '(dynamic) => dynamic' of 'f' where _Future is from dart:async

How can I fix this?

Thanks

Body:
You have the wrong type for the argument of .then().  Try:

.then((_) => play2(pickRandomSoundFrequency()))

You need to pass a function to be called, not call the function when constructing the arguments to then.